<template>
  <div class="comprehensive-score-test">
    <div v-if="!sharedData" class="test-header">
      <h2>综合评分数据测试 - 所有支行</h2>
      <p class="subtitle">同时获取所有支行的30个评分指标数据</p>
    </div>

    <div v-if="!sharedData" class="test-controls">
      <div class="control-group">
        <label>业务日期：</label>
        <input v-model="bussDate" type="text" placeholder="格式：YYYYMMDD" />
      </div>
      <button 
        @click="loadAllData" 
        :disabled="isLoading"
        class="btn-load"
      >
        {{ isLoading ? '加载中...' : '获取所有支行数据' }}
      </button>
      <button 
        @click="exportToExcel" 
        :disabled="isLoading || Object.keys(scoreData).length === 0"
        class="btn-export"
      >
        📥 导出Excel
      </button>
    </div>
    
    <!-- 对话框模式下的导出按钮 -->
    <div v-if="sharedData" class="dialog-export">
      <button 
        @click="exportToExcel" 
        :disabled="Object.keys(scoreData).length === 0"
        class="btn-export"
      >
        📥 导出Excel
      </button>
    </div>

    <div v-if="isLoading" class="loading">
      <div class="spinner"></div>
      <p>正在加载数据，请稍候...</p>
    </div>

    <div v-if="error" class="error-message">
      <h3>❌ 错误</h3>
      <p>{{ error }}</p>
    </div>

    <div v-if="!isLoading && Object.keys(scoreData).length > 0" class="results">
      <h3>📊 数据获取结果</h3>
      
      <div class="summary">
        <div class="summary-item">
          <span class="label">支行数量：</span>
          <span class="value">{{ totalBranches }}</span>
        </div>
        <div class="summary-item">
          <span class="label">每支行指标数：</span>
          <span class="value">30</span>
        </div>
        <div class="summary-item success">
          <span class="label">数据获取成功：</span>
          <span class="value">{{ successBranches }} 个支行</span>
        </div>
        <div class="summary-item error" v-if="failedBranches > 0">
          <span class="label">失败：</span>
          <span class="value">{{ failedBranches }} 个支行</span>
        </div>
      </div>

      <!-- 支行列表 -->
      <div class="branches-list">
        <div 
          v-for="(branch, index) in sortedScoreData" 
          :key="branch.orgNo"
          class="branch-item"
        >
          <div class="branch-header" @click="toggleBranch(branch.orgNo)">
            <h3>
              <span class="toggle-icon">{{ expandedBranches.includes(branch.orgNo) ? '▼' : '▶' }}</span>
              {{ getOrgName(branch.orgNo) }} ({{ branch.orgNo }})
            </h3>
            <div class="branch-stats">
              <span class="stat success">✅ {{ getBranchSuccessCount(branch.branchData) }}</span>
              <span class="stat fail" v-if="getBranchFailCount(branch.branchData) > 0">❌ {{ getBranchFailCount(branch.branchData) }}</span>
              <span class="stat weighted-sum" v-if="getBranchWeightedScoreSum(branch.orgNo)">
                📊 加权得分总和: {{ getBranchWeightedScoreSum(branch.orgNo).toFixed(2) }}
              </span>
              <span class="stat rank" v-if="getBranchRank(branch.orgNo)">
                🏆 排名: {{ getBranchRank(branch.orgNo) }}
              </span>
              <span class="stat abnormal" v-if="getAbnormalIndicators(branch.orgNo).length > 0">
                ⚡ 异常指标: {{ getAbnormalIndicators(branch.orgNo).length }}项
              </span>
            </div>
            <div v-if="getAbnormalIndicators(branch.orgNo).length > 0" class="abnormal-indicators">
              <div class="abnormal-title">🔍 异常指标明细（Z-score > 1 或 < -1）：</div>
              <div class="abnormal-list">
                <div 
                  v-for="indicator in getAbnormalIndicators(branch.orgNo)" 
                  :key="indicator.key"
                  class="abnormal-item"
                  :class="indicator.type"
                >
                  <span class="indicator-name">{{ indicator.name }}</span>
                  <span class="indicator-value">值: {{ indicator.value }}</span>
                  <span class="indicator-zscore" :class="indicator.zScoreClass">
                    Z-score: {{ indicator.zScore }}
                  </span>
                  <span class="indicator-score">得分: {{ indicator.score }}分</span>
                </div>
              </div>
            </div>
          </div>

          <div v-if="expandedBranches.includes(branch.orgNo)" class="branch-content">
            <div class="indicator-list">
              <!-- 不良贷款指标组 -->
              <div v-if="hasBadLoanIndicators(branch.branchData)" class="indicator-group">
                <div class="group-header">
                  <h3>⚠️ 不良贷款指标组</h3>
                  <div class="group-header-right">
                    <span class="group-subtitle">3个子指标</span>
                    <span v-if="getBadLoanGroupScore(branch.orgNo)" class="group-score-badge">
                      汇总得分: {{ getBadLoanGroupScore(branch.orgNo).totalWeightedScore }}
                    </span>
                  </div>
                </div>
                <div class="group-content">
                  <div 
                    v-for="(data, key) in getBadLoanIndicators(branch.branchData)" 
                    :key="key"
                    class="indicator-item grouped"
                    :class="{ success: data.success, failed: !data.success }"
                  >
                    <div class="indicator-header compact">
                      <h4>
                        <span class="status-icon">{{ data.success ? '✅' : '❌' }}</span>
                        {{ data.name }}
                      </h4>
                      <span class="indicator-type">{{ getTypeLabel(data) }}</span>
                    </div>
                    
                    <div v-if="data.success" class="indicator-content">
                      <div v-if="isSimpleType(data)" class="data-section compact">
                        <div v-if="data.result?.datas && data.result.datas.length > 0" class="migration-rate-display">
                          <div class="rate-value">
                            <span class="label">指标值：</span>
                            <span class="value">{{ data.result.datas[0][3] }}</span>
                          </div>
                          <div class="rate-score" v-if="getIndicatorScore(data.result.datas[0][2], key)">
                            <span class="label">Z-score评分：</span>
                            <span class="score-badge" :class="getScoreClass(getIndicatorScore(data.result.datas[0][2], key).score)">
                              {{ getIndicatorScore(data.result.datas[0][2], key).score }}分
                            </span>
                            <span class="z-value">Z: {{ getIndicatorScore(data.result.datas[0][2], key).zScore }}</span>
                          </div>
                          <div class="rate-weight" v-if="getIndicatorScore(data.result.datas[0][2], key) && getIndicatorScore(data.result.datas[0][2], key).weight">
                            <span class="label">权重：</span>
                            <span class="weight-badge">{{ getIndicatorScore(data.result.datas[0][2], key).weight }}%</span>
                            <span class="weighted-score">→ {{ calculateWeightedScore(getIndicatorScore(data.result.datas[0][2], key)) }}</span>
                          </div>
                          <div class="rate-rank" v-if="getIndicatorScore(data.result.datas[0][2], key) && getIndicatorScore(data.result.datas[0][2], key).rank">
                            <span class="label">排名：</span>
                            <span class="rank-badge">{{ getIndicatorScore(data.result.datas[0][2], key).rank }}</span>
                          </div>
                        </div>
                      </div>
                      
                      <!-- 增长型指标（不良贷款增幅） -->
                      <div v-if="data.type === 'growth'" class="data-section">
                        <!-- 增长率计算结果 -->
                        <div v-if="data.endResult?.datas && data.startResult?.datas && data.endResult.datas.length > 0 && data.startResult.datas.length > 0" class="growth-summary">
                          <div class="summary-item">
                            <span class="label">期初值：</span>
                            <span class="value">{{ formatNumber(parseFloat(data.startResult.datas[0][3])) }}</span>
                          </div>
                          <div class="summary-item">
                            <span class="label">期末值：</span>
                            <span class="value">{{ formatNumber(parseFloat(data.endResult.datas[0][3])) }}</span>
                          </div>
                          <div class="summary-item highlight">
                            <span class="label">增长率：</span>
                            <span class="value">{{ calculateGrowthRate(data.endResult.datas[0][3], data.startResult.datas[0][3]) }}%</span>
                          </div>
                          <div class="summary-item score" v-if="getIndicatorScore(data.endResult.datas[0][2], key)">
                            <span class="label">Z-score评分：</span>
                            <span class="score-badge" :class="getScoreClass(getIndicatorScore(data.endResult.datas[0][2], key).score)">
                              {{ getIndicatorScore(data.endResult.datas[0][2], key).score }}分
                            </span>
                            <span class="z-value">Z: {{ getIndicatorScore(data.endResult.datas[0][2], key).zScore }}</span>
                          </div>
                          <div class="summary-item weight" v-if="getIndicatorScore(data.endResult.datas[0][2], key) && getIndicatorScore(data.endResult.datas[0][2], key).weight">
                            <span class="label">权重：</span>
                            <span class="weight-badge">{{ getIndicatorScore(data.endResult.datas[0][2], key).weight }}%</span>
                            <span class="weighted-score">→ {{ calculateWeightedScore(getIndicatorScore(data.endResult.datas[0][2], key)) }}</span>
                          </div>
                          <div class="summary-item rank" v-if="getIndicatorScore(data.endResult.datas[0][2], key) && getIndicatorScore(data.endResult.datas[0][2], key).rank">
                            <span class="label">排名：</span>
                            <span class="rank-badge">{{ getIndicatorScore(data.endResult.datas[0][2], key).rank }}</span>
                          </div>
                        </div>
                      </div>

                      <!-- 带核销的增长型指标（不良贷款增幅+核销） -->
                      <div v-if="data.type === 'growthWithWriteOff'" class="data-section">
                        <!-- 增长率计算结果（包含核销） -->
                        <div v-if="data.endResult?.datas && data.startResult?.datas && data.endResult.datas.length > 0 && data.startResult.datas.length > 0" class="growth-summary">
                          <div class="summary-item">
                            <span class="label">期初值：</span>
                            <span class="value">{{ formatNumber(parseFloat(data.startResult.datas[0][3])) }}</span>
                          </div>
                          <div class="summary-item">
                            <span class="label">期末值：</span>
                            <span class="value">{{ formatNumber(parseFloat(data.endResult.datas[0][3])) }}</span>
                          </div>
                          <div class="summary-item" v-if="data.writeOffResult?.datas && data.writeOffResult.datas.length > 0">
                            <span class="label">核销金额：</span>
                            <span class="value">{{ formatNumber(sumValues(data.writeOffResult.datas)) }}</span>
                          </div>
                          <div class="summary-item" v-else>
                            <span class="label">核销金额：</span>
                            <span class="value">0.00</span>
                          </div>
                          <div class="summary-item highlight">
                            <span class="label">增长率（含核销）：</span>
                            <span class="value">{{ calculateGrowthRateWithWriteOff(data) }}%</span>
                          </div>
                          <div class="summary-item score" v-if="getIndicatorScore(data.endResult.datas[0][2], key)">
                            <span class="label">Z-score评分：</span>
                            <span class="score-badge" :class="getScoreClass(getIndicatorScore(data.endResult.datas[0][2], key).score)">
                              {{ getIndicatorScore(data.endResult.datas[0][2], key).score }}分
                            </span>
                            <span class="z-value">Z: {{ getIndicatorScore(data.endResult.datas[0][2], key).zScore }}</span>
                          </div>
                          <div class="summary-item weight" v-if="getIndicatorScore(data.endResult.datas[0][2], key) && getIndicatorScore(data.endResult.datas[0][2], key).weight">
                            <span class="label">权重：</span>
                            <span class="weight-badge">{{ getIndicatorScore(data.endResult.datas[0][2], key).weight }}%</span>
                            <span class="weighted-score">→ {{ calculateWeightedScore(getIndicatorScore(data.endResult.datas[0][2], key)) }}</span>
                          </div>
                          <div class="summary-item rank" v-if="getIndicatorScore(data.endResult.datas[0][2], key) && getIndicatorScore(data.endResult.datas[0][2], key).rank">
                            <span class="label">排名：</span>
                            <span class="rank-badge">{{ getIndicatorScore(data.endResult.datas[0][2], key).rank }}</span>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>

              <!-- 关注类贷款指标组 -->
              <div v-if="hasConcernLoanIndicators(branch.branchData)" class="indicator-group concern-loan-group">
                <div class="group-header">
                  <h3>⚠️ 关注类贷款指标组</h3>
                  <div class="group-header-right">
                    <span class="group-subtitle">3个子指标</span>
                    <span v-if="getConcernLoanGroupScore(branch.orgNo)" class="group-score-badge">
                      汇总得分: {{ getConcernLoanGroupScore(branch.orgNo).totalWeightedScore }}
                    </span>
                  </div>
                </div>
                <div class="group-content">
                  <div 
                    v-for="(data, key) in getConcernLoanIndicators(branch.branchData)" 
                    :key="key"
                    class="indicator-item grouped"
                    :class="{ success: data.success, failed: !data.success }"
                  >
                    <div class="indicator-header compact">
                      <h4>
                        <span class="status-icon">{{ data.success ? '✅' : '❌' }}</span>
                        {{ data.name }}
                      </h4>
                      <span class="indicator-type">{{ getTypeLabel(data) }}</span>
                    </div>
                    
                    <div v-if="data.success" class="indicator-content">
                      <div v-if="isSimpleType(data)" class="data-section compact">
                        <div v-if="data.result?.datas && data.result.datas.length > 0" class="migration-rate-display">
                          <div class="rate-value">
                            <span class="label">指标值：</span>
                            <span class="value">{{ data.result.datas[0][3] }}</span>
                          </div>
                          <div class="rate-score" v-if="getIndicatorScore(data.result.datas[0][2], key)">
                            <span class="label">Z-score评分：</span>
                            <span class="score-badge" :class="getScoreClass(getIndicatorScore(data.result.datas[0][2], key).score)">
                              {{ getIndicatorScore(data.result.datas[0][2], key).score }}分
                            </span>
                            <span class="z-value">Z: {{ getIndicatorScore(data.result.datas[0][2], key).zScore }}</span>
                          </div>
                          <div class="rate-weight" v-if="getIndicatorScore(data.result.datas[0][2], key) && getIndicatorScore(data.result.datas[0][2], key).weight">
                            <span class="label">权重：</span>
                            <span class="weight-badge">{{ getIndicatorScore(data.result.datas[0][2], key).weight }}%</span>
                            <span class="weighted-score">→ {{ calculateWeightedScore(getIndicatorScore(data.result.datas[0][2], key)) }}</span>
                          </div>
                          <div class="rate-rank" v-if="getIndicatorScore(data.result.datas[0][2], key) && getIndicatorScore(data.result.datas[0][2], key).rank">
                            <span class="label">排名：</span>
                            <span class="rank-badge">{{ getIndicatorScore(data.result.datas[0][2], key).rank }}</span>
                          </div>
                        </div>
                      </div>
                      
                      <!-- 增长型指标 -->
                      <div v-if="data.type === 'growth'" class="data-section">
                        <!-- 增长率计算结果 -->
                        <div v-if="data.endResult?.datas && data.startResult?.datas && data.endResult.datas.length > 0 && data.startResult.datas.length > 0" class="growth-summary">
                          <div class="summary-item">
                            <span class="label">期初值：</span>
                            <span class="value">{{ formatNumber(parseFloat(data.startResult.datas[0][3])) }}</span>
                          </div>
                          <div class="summary-item">
                            <span class="label">期末值：</span>
                            <span class="value">{{ formatNumber(parseFloat(data.endResult.datas[0][3])) }}</span>
                          </div>
                          <div class="summary-item highlight">
                            <span class="label">增长率：</span>
                            <span class="value">{{ calculateGrowthRate(data.endResult.datas[0][3], data.startResult.datas[0][3]) }}%</span>
                          </div>
                          <div class="summary-item score" v-if="getIndicatorScore(data.endResult.datas[0][2], key)">
                            <span class="label">Z-score评分：</span>
                            <span class="score-badge" :class="getScoreClass(getIndicatorScore(data.endResult.datas[0][2], key).score)">
                              {{ getIndicatorScore(data.endResult.datas[0][2], key).score }}分
                            </span>
                            <span class="z-value">Z: {{ getIndicatorScore(data.endResult.datas[0][2], key).zScore }}</span>
                          </div>
                          <div class="summary-item weight" v-if="getIndicatorScore(data.endResult.datas[0][2], key) && getIndicatorScore(data.endResult.datas[0][2], key).weight">
                            <span class="label">权重：</span>
                            <span class="weight-badge">{{ getIndicatorScore(data.endResult.datas[0][2], key).weight }}%</span>
                            <span class="weighted-score">→ {{ calculateWeightedScore(getIndicatorScore(data.endResult.datas[0][2], key)) }}</span>
                          </div>
                          <div class="summary-item rank" v-if="getIndicatorScore(data.endResult.datas[0][2], key) && getIndicatorScore(data.endResult.datas[0][2], key).rank">
                            <span class="label">排名：</span>
                            <span class="rank-badge">{{ getIndicatorScore(data.endResult.datas[0][2], key).rank }}</span>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>

              <!-- 贷款迁徙率指标组 -->
              <div v-if="hasLoanMigrationRates(branch.branchData)" class="indicator-group">
                <div class="group-header">
                  <h3>📊 贷款迁徙率指标组</h3>
                  <div class="group-header-right">
                    <span class="group-subtitle">4个子指标</span>
                    <span v-if="getLoanMigrationGroupScore(branch.orgNo)" class="group-score-badge">
                      汇总得分: {{ getLoanMigrationGroupScore(branch.orgNo).totalWeightedScore }}
                    </span>
                  </div>
                </div>
                <div class="group-content">
                  <div 
                    v-for="(data, key) in getLoanMigrationRates(branch.branchData)" 
                    :key="key"
                    class="indicator-item grouped"
                    :class="{ success: data.success, failed: !data.success }"
                  >
                    <div class="indicator-header compact">
                      <h4>
                        <span class="status-icon">{{ data.success ? '✅' : '❌' }}</span>
                        {{ data.name }}
                      </h4>
                      <span class="indicator-type">{{ getTypeLabel(data) }}</span>
                    </div>
                    
                    <div v-if="data.success" class="indicator-content">
                      <div v-if="isSimpleType(data)" class="data-section compact">
                        <div v-if="data.result?.datas && data.result.datas.length > 0" class="migration-rate-display">
                          <div class="rate-value">
                            <span class="label">指标值：</span>
                            <span class="value">{{ data.result.datas[0][3] }}</span>
                          </div>
                          <div class="rate-score" v-if="getIndicatorScore(data.result.datas[0][2], key)">
                            <span class="label">Z-score评分：</span>
                            <span class="score-badge" :class="getScoreClass(getIndicatorScore(data.result.datas[0][2], key).score)">
                              {{ getIndicatorScore(data.result.datas[0][2], key).score }}分
                            </span>
                            <span class="z-value">Z: {{ getIndicatorScore(data.result.datas[0][2], key).zScore }}</span>
                          </div>
                          <div class="rate-weight" v-if="getIndicatorScore(data.result.datas[0][2], key) && getIndicatorScore(data.result.datas[0][2], key).weight">
                            <span class="label">权重：</span>
                            <span class="weight-badge">{{ getIndicatorScore(data.result.datas[0][2], key).weight }}%</span>
                            <span class="weighted-score">→ {{ calculateWeightedScore(getIndicatorScore(data.result.datas[0][2], key)) }}</span>
                          </div>
                          <div class="rate-rank" v-if="getIndicatorScore(data.result.datas[0][2], key) && getIndicatorScore(data.result.datas[0][2], key).rank">
                            <span class="label">排名：</span>
                            <span class="rank-badge">{{ getIndicatorScore(data.result.datas[0][2], key).rank }}</span>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>

              <!-- 贷款集中度指标组 -->
              <div v-if="hasLoanConcentrationIndicators(branch.branchData)" class="indicator-group">
                <div class="group-header">
                  <h3>🎯 贷款集中度指标组</h3>
                  <div class="group-header-right">
                    <span class="group-subtitle">2个子指标</span>
                    <span v-if="getLoanConcentrationGroupScore(branch.orgNo)" class="group-score-badge">
                      汇总得分: {{ getLoanConcentrationGroupScore(branch.orgNo).totalWeightedScore }}
                    </span>
                  </div>
                </div>
                <div class="group-content">
                  <div 
                    v-for="(data, key) in getLoanConcentrationIndicators(branch.branchData)" 
                    :key="key"
                    class="indicator-item grouped"
                    :class="{ success: data.success, failed: !data.success }"
                  >
                    <div class="indicator-header compact">
                      <h4>
                        <span class="status-icon">{{ data.success ? '✅' : '❌' }}</span>
                        {{ data.name }}
                      </h4>
                      <span class="indicator-type">{{ getTypeLabel(data) }}</span>
                    </div>
                    
                    <div v-if="data.success" class="indicator-content">
                      <div v-if="isSimpleType(data)" class="data-section compact">
                        <div v-if="data.result?.datas && data.result.datas.length > 0" class="migration-rate-display">
                          <div class="rate-value">
                            <span class="label">指标值：</span>
                            <span class="value">{{ formatNumber(parseFloat(data.result.datas[0][3])) }}</span>
                          </div>
                          <div class="rate-score" v-if="getIndicatorScore(data.result.datas[0][2], key)">
                            <span class="label">Z-score评分：</span>
                            <span class="score-badge" :class="getScoreClass(getIndicatorScore(data.result.datas[0][2], key).score)">
                              {{ getIndicatorScore(data.result.datas[0][2], key).score }}分
                            </span>
                            <span class="z-value">Z: {{ getIndicatorScore(data.result.datas[0][2], key).zScore }}</span>
                          </div>
                          <div class="rate-weight" v-if="getIndicatorScore(data.result.datas[0][2], key) && getIndicatorScore(data.result.datas[0][2], key).weight">
                            <span class="label">权重：</span>
                            <span class="weight-badge">{{ getIndicatorScore(data.result.datas[0][2], key).weight }}%</span>
                            <span class="weighted-score">→ {{ calculateWeightedScore(getIndicatorScore(data.result.datas[0][2], key)) }}</span>
                          </div>
                          <div class="rate-rank" v-if="getIndicatorScore(data.result.datas[0][2], key) && getIndicatorScore(data.result.datas[0][2], key).rank">
                            <span class="label">排名：</span>
                            <span class="rank-badge">{{ getIndicatorScore(data.result.datas[0][2], key).rank }}</span>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>

              <!-- 存款业务指标组 -->
              <div v-if="hasDepositIndicators(branch.branchData)" class="indicator-group deposit-group">
                <div class="group-header">
                  <h3>💰 存款业务指标组</h3>
                  <div class="group-header-right">
                    <span class="group-subtitle">4个子指标</span>
                    <span v-if="getDepositGroupScore(branch.orgNo)" class="group-score-badge">
                      汇总得分: {{ getDepositGroupScore(branch.orgNo).totalWeightedScore }}
                    </span>
                  </div>
                </div>
                <div class="group-content">
                  <div 
                    v-for="(data, key) in getDepositIndicators(branch.branchData)" 
                    :key="key"
                    class="indicator-item grouped"
                    :class="{ success: data.success, failed: !data.success }"
                  >
                    <div class="indicator-header compact">
                      <h4>
                        <span class="status-icon">{{ data.success ? '✅' : '❌' }}</span>
                        {{ data.name }}
                      </h4>
                      <span class="indicator-type">{{ getTypeLabel(data) }}</span>
                    </div>
                    
                    <div v-if="data.success" class="indicator-content">
                      <!-- 增长型指标 -->
                      <div v-if="data.type === 'growth' || data.type === 'increase'" class="data-section">
                        <div v-if="data.endResult?.datas && data.startResult?.datas && data.endResult.datas.length > 0 && data.startResult.datas.length > 0" class="growth-summary">
                          <div class="summary-item">
                            <span class="label">期初值：</span>
                            <span class="value">{{ formatNumber(parseFloat(data.startResult.datas[0][3])) }}</span>
                          </div>
                          <div class="summary-item">
                            <span class="label">期末值：</span>
                            <span class="value">{{ formatNumber(parseFloat(data.endResult.datas[0][3])) }}</span>
                          </div>
                          <div class="summary-item highlight" v-if="data.type === 'growth'">
                            <span class="label">增长率：</span>
                            <span class="value">{{ calculateGrowthRate(data.endResult.datas[0][3], data.startResult.datas[0][3]) }}%</span>
                          </div>
                          <div class="summary-item highlight" v-if="data.type === 'increase'">
                            <span class="label">增加值：</span>
                            <span class="value">{{ formatNumber(parseFloat(data.endResult.datas[0][3]) - parseFloat(data.startResult.datas[0][3])) }}</span>
                          </div>
                          <div class="summary-item score" v-if="getIndicatorScore(data.endResult.datas[0][2], key)">
                            <span class="label">Z-score评分：</span>
                            <span class="score-badge" :class="getScoreClass(getIndicatorScore(data.endResult.datas[0][2], key).score)">
                              {{ getIndicatorScore(data.endResult.datas[0][2], key).score }}分
                            </span>
                            <span class="z-value">Z: {{ getIndicatorScore(data.endResult.datas[0][2], key).zScore }}</span>
                          </div>
                          <div class="summary-item weight" v-if="getIndicatorScore(data.endResult.datas[0][2], key) && getIndicatorScore(data.endResult.datas[0][2], key).weight">
                            <span class="label">权重：</span>
                            <span class="weight-badge">{{ getIndicatorScore(data.endResult.datas[0][2], key).weight }}%</span>
                            <span class="weighted-score">→ {{ calculateWeightedScore(getIndicatorScore(data.endResult.datas[0][2], key)) }}</span>
                          </div>
                          <div class="summary-item rank" v-if="getIndicatorScore(data.endResult.datas[0][2], key) && getIndicatorScore(data.endResult.datas[0][2], key).rank">
                            <span class="label">排名：</span>
                            <span class="rank-badge">{{ getIndicatorScore(data.endResult.datas[0][2], key).rank }}</span>
                          </div>
                        </div>
                      </div>

                      <!-- 比率型指标 -->
                      <div v-if="data.type === 'ratio'" class="data-section">
                        <div v-if="data.numeratorResult?.datas && data.denominatorResult?.datas" class="ratio-summary">
                          <div class="summary-item">
                            <span class="label">分子：</span>
                            <span class="value">{{ formatNumber(sumValues(data.numeratorResult.datas)) }}</span>
                          </div>
                          <div class="summary-item">
                            <span class="label">分母：</span>
                            <span class="value">{{ formatNumber(sumValues(data.denominatorResult.datas)) }}</span>
                          </div>
                          <div class="summary-item highlight">
                            <span class="label">比率：</span>
                            <span class="value">{{ calculateRatio(data.numeratorResult.datas, data.denominatorResult.datas) }}%</span>
                          </div>
                          <div class="summary-item score" v-if="data.numeratorResult.datas[0] && getIndicatorScore(data.numeratorResult.datas[0][2], key)">
                            <span class="label">Z-score评分：</span>
                            <span class="score-badge" :class="getScoreClass(getIndicatorScore(data.numeratorResult.datas[0][2], key).score)">
                              {{ getIndicatorScore(data.numeratorResult.datas[0][2], key).score }}分
                            </span>
                            <span class="z-value">Z: {{ getIndicatorScore(data.numeratorResult.datas[0][2], key).zScore }}</span>
                          </div>
                          <div class="summary-item weight" v-if="data.numeratorResult.datas[0] && getIndicatorScore(data.numeratorResult.datas[0][2], key) && getIndicatorScore(data.numeratorResult.datas[0][2], key).weight">
                            <span class="label">权重：</span>
                            <span class="weight-badge">{{ getIndicatorScore(data.numeratorResult.datas[0][2], key).weight }}%</span>
                            <span class="weighted-score">→ {{ calculateWeightedScore(getIndicatorScore(data.numeratorResult.datas[0][2], key)) }}</span>
                          </div>
                          <div class="summary-item rank" v-if="data.numeratorResult.datas[0] && getIndicatorScore(data.numeratorResult.datas[0][2], key) && getIndicatorScore(data.numeratorResult.datas[0][2], key).rank">
                            <span class="label">排名：</span>
                            <span class="rank-badge">{{ getIndicatorScore(data.numeratorResult.datas[0][2], key).rank }}</span>
                          </div>
                        </div>
                      </div>

                      <!-- 偏离度型指标 -->
                      <div v-if="data.type === 'deviation'" class="data-section">
                        <div v-if="data.monthEndResult?.datas && data.monthAvgResult?.datas" class="deviation-summary">
                          <div class="summary-item">
                            <span class="label">月末余额：</span>
                            <span class="value">{{ formatNumber(parseFloat(data.monthEndResult.datas[0][3])) }}</span>
                          </div>
                          <div class="summary-item">
                            <span class="label">月日均余额：</span>
                            <span class="value">{{ formatNumber(sumValues(data.monthAvgResult.datas)) }}</span>
                          </div>
                          <div class="summary-item highlight">
                            <span class="label">偏离度：</span>
                            <span class="value">{{ calculateDeviation(data.monthEndResult.datas[0][3], data.monthAvgResult.datas) }}%</span>
                          </div>
                          <div class="summary-item score" v-if="getIndicatorScore(data.monthEndResult.datas[0][2], key)">
                            <span class="label">Z-score评分：</span>
                            <span class="score-badge" :class="getScoreClass(getIndicatorScore(data.monthEndResult.datas[0][2], key).score)">
                              {{ getIndicatorScore(data.monthEndResult.datas[0][2], key).score }}分
                            </span>
                            <span class="z-value">Z: {{ getIndicatorScore(data.monthEndResult.datas[0][2], key).zScore }}</span>
                          </div>
                          <div class="summary-item weight" v-if="getIndicatorScore(data.monthEndResult.datas[0][2], key) && getIndicatorScore(data.monthEndResult.datas[0][2], key).weight">
                            <span class="label">权重：</span>
                            <span class="weight-badge">{{ getIndicatorScore(data.monthEndResult.datas[0][2], key).weight }}%</span>
                            <span class="weighted-score">→ {{ calculateWeightedScore(getIndicatorScore(data.monthEndResult.datas[0][2], key)) }}</span>
                          </div>
                          <div class="summary-item rank" v-if="getIndicatorScore(data.monthEndResult.datas[0][2], key) && getIndicatorScore(data.monthEndResult.datas[0][2], key).rank">
                            <span class="label">排名：</span>
                            <span class="rank-badge">{{ getIndicatorScore(data.monthEndResult.datas[0][2], key).rank }}</span>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>

              <!-- 贷款业务指标组 -->
              <div v-if="hasLoanIndicators(branch.branchData)" class="indicator-group loan-group">
                <div class="group-header">
                  <h3>💼 贷款业务指标组</h3>
                  <div class="group-header-right">
                    <span class="group-subtitle">4个子指标</span>
                    <span v-if="getLoanGroupScore(branch.orgNo)" class="group-score-badge">
                      汇总得分: {{ getLoanGroupScore(branch.orgNo).totalWeightedScore }}
                    </span>
                  </div>
                </div>
                <div class="group-content">
                  <div 
                    v-for="(data, key) in getLoanIndicators(branch.branchData)" 
                    :key="key"
                    class="indicator-item grouped"
                    :class="{ success: data.success, failed: !data.success }"
                  >
                    <div class="indicator-header compact">
                      <h4>
                        <span class="status-icon">{{ data.success ? '✅' : '❌' }}</span>
                        {{ data.name }}
                      </h4>
                      <span class="indicator-type">{{ getTypeLabel(data) }}</span>
                    </div>
                    
                    <div v-if="data.success" class="indicator-content">
                      <!-- 增长型或增加值型指标 -->
                      <div v-if="data.type === 'growth' || data.type === 'increase'" class="data-section">
                        <div v-if="data.endResult?.datas && data.startResult?.datas && data.endResult.datas.length > 0 && data.startResult.datas.length > 0" class="growth-summary">
                          <div class="summary-item">
                            <span class="label">期初值：</span>
                            <span class="value">{{ formatNumber(parseFloat(data.startResult.datas[0][3])) }}</span>
                          </div>
                          <div class="summary-item">
                            <span class="label">期末值：</span>
                            <span class="value">{{ formatNumber(parseFloat(data.endResult.datas[0][3])) }}</span>
                          </div>
                          <div class="summary-item highlight" v-if="data.type === 'growth'">
                            <span class="label">增长率：</span>
                            <span class="value">{{ calculateGrowthRate(data.endResult.datas[0][3], data.startResult.datas[0][3]) }}%</span>
                          </div>
                          <div class="summary-item highlight" v-if="data.type === 'increase'">
                            <span class="label">增加值：</span>
                            <span class="value">{{ formatNumber(parseFloat(data.endResult.datas[0][3]) - parseFloat(data.startResult.datas[0][3])) }}</span>
                          </div>
                          <div class="summary-item score" v-if="getIndicatorScore(data.endResult.datas[0][2], key)">
                            <span class="label">Z-score评分：</span>
                            <span class="score-badge" :class="getScoreClass(getIndicatorScore(data.endResult.datas[0][2], key).score)">
                              {{ getIndicatorScore(data.endResult.datas[0][2], key).score }}分
                            </span>
                            <span class="z-value">Z: {{ getIndicatorScore(data.endResult.datas[0][2], key).zScore }}</span>
                          </div>
                          <div class="summary-item weight" v-if="getIndicatorScore(data.endResult.datas[0][2], key) && getIndicatorScore(data.endResult.datas[0][2], key).weight">
                            <span class="label">权重：</span>
                            <span class="weight-badge">{{ getIndicatorScore(data.endResult.datas[0][2], key).weight }}%</span>
                            <span class="weighted-score">→ {{ calculateWeightedScore(getIndicatorScore(data.endResult.datas[0][2], key)) }}</span>
                          </div>
                          <div class="summary-item rank" v-if="getIndicatorScore(data.endResult.datas[0][2], key) && getIndicatorScore(data.endResult.datas[0][2], key).rank">
                            <span class="label">排名：</span>
                            <span class="rank-badge">{{ getIndicatorScore(data.endResult.datas[0][2], key).rank }}</span>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>

              <!-- 中间业务指标组 -->
              <div v-if="hasIntermediateIncomeIndicators(branch.branchData)" class="indicator-group intermediate-income-group">
                <div class="group-header">
                  <h3>💰 中间业务指标组</h3>
                  <div class="group-header-right">
                    <span class="group-subtitle">6个子指标</span>
                    <span v-if="getIntermediateIncomeGroupScore(branch.orgNo)" class="group-score-badge">
                      汇总得分: {{ getIntermediateIncomeGroupScore(branch.orgNo).totalWeightedScore }}
                    </span>
                  </div>
                </div>
                <div class="group-content">
                  <div 
                    v-for="(data, key) in getIntermediateIncomeIndicators(branch.branchData)" 
                    :key="key"
                    class="indicator-item grouped"
                    :class="{ success: data.success, failed: !data.success }"
                  >
                    <div class="indicator-header compact">
                      <h4>
                        <span class="status-icon">{{ data.success ? '✅' : '❌' }}</span>
                        {{ data.name }}
                      </h4>
                      <span class="indicator-type">{{ getTypeLabel(data) }}</span>
                    </div>
                    
                    <div v-if="data.success" class="indicator-content">
                      <!-- 增长型或增加值型指标 -->
                      <div v-if="data.type === 'growth' || data.type === 'increase'" class="data-section">
                        <div v-if="data.endResult?.datas && data.startResult?.datas && data.endResult.datas.length > 0 && data.startResult.datas.length > 0" class="growth-summary">
                          <div class="summary-item">
                            <span class="label">期初值：</span>
                            <span class="value">{{ formatNumber(sumValues(data.startResult.datas)) }}</span>
                          </div>
                          <div class="summary-item">
                            <span class="label">期末值：</span>
                            <span class="value">{{ formatNumber(sumValues(data.endResult.datas)) }}</span>
                          </div>
                          <div class="summary-item highlight" v-if="data.type === 'growth'">
                            <span class="label">增长率：</span>
                            <span class="value">{{ calculateGrowthRateFromSum(data.endResult.datas, data.startResult.datas) }}%</span>
                          </div>
                          <div class="summary-item highlight" v-if="data.type === 'increase'">
                            <span class="label">增加值：</span>
                            <span class="value">{{ formatNumber(sumValues(data.endResult.datas) - sumValues(data.startResult.datas)) }}</span>
                          </div>
                          <div class="summary-item score" v-if="getIndicatorScore(data.endResult.datas[0][2], key)">
                            <span class="label">Z-score评分：</span>
                            <span class="score-badge" :class="getScoreClass(getIndicatorScore(data.endResult.datas[0][2], key).score)">
                              {{ getIndicatorScore(data.endResult.datas[0][2], key).score }}分
                            </span>
                            <span class="z-value">Z: {{ getIndicatorScore(data.endResult.datas[0][2], key).zScore }}</span>
                          </div>
                          <div class="summary-item weight" v-if="getIndicatorScore(data.endResult.datas[0][2], key) && getIndicatorScore(data.endResult.datas[0][2], key).weight">
                            <span class="label">权重：</span>
                            <span class="weight-badge">{{ getIndicatorScore(data.endResult.datas[0][2], key).weight }}%</span>
                            <span class="weighted-score">→ {{ calculateWeightedScore(getIndicatorScore(data.endResult.datas[0][2], key)) }}</span>
                          </div>
                          <div class="summary-item rank" v-if="getIndicatorScore(data.endResult.datas[0][2], key) && getIndicatorScore(data.endResult.datas[0][2], key).rank">
                            <span class="label">排名：</span>
                            <span class="rank-badge">{{ getIndicatorScore(data.endResult.datas[0][2], key).rank }}</span>
                          </div>
                        </div>
                      </div>
                      
                      <!-- 比率型指标 -->
                      <div v-else-if="data.type === 'ratio'" class="data-section">
                        <div v-if="data.numeratorResult?.datas && data.denominatorResult?.datas" class="ratio-summary">
                          <div class="summary-item">
                            <span class="label">分子：</span>
                            <span class="value">{{ formatNumber(sumValues(data.numeratorResult.datas)) }}</span>
                          </div>
                          <div class="summary-item">
                            <span class="label">分母：</span>
                            <span class="value">{{ formatNumber(sumValues(data.denominatorResult.datas)) }}</span>
                          </div>
                          <div class="summary-item highlight">
                            <span class="label">比率：</span>
                            <span class="value">{{ calculateRatio(data.numeratorResult.datas, data.denominatorResult.datas, key) }}%</span>
                          </div>
                          <div class="summary-item score" v-if="getIndicatorScore(data.numeratorResult.datas[0][2], key)">
                            <span class="label">Z-score评分：</span>
                            <span class="score-badge" :class="getScoreClass(getIndicatorScore(data.numeratorResult.datas[0][2], key).score)">
                              {{ getIndicatorScore(data.numeratorResult.datas[0][2], key).score }}分
                            </span>
                            <span class="z-value">Z: {{ getIndicatorScore(data.numeratorResult.datas[0][2], key).zScore }}</span>
                          </div>
                          <div class="summary-item weight" v-if="getIndicatorScore(data.numeratorResult.datas[0][2], key) && getIndicatorScore(data.numeratorResult.datas[0][2], key).weight">
                            <span class="label">权重：</span>
                            <span class="weight-badge">{{ getIndicatorScore(data.numeratorResult.datas[0][2], key).weight }}%</span>
                            <span class="weighted-score">→ {{ calculateWeightedScore(getIndicatorScore(data.numeratorResult.datas[0][2], key)) }}</span>
                          </div>
                          <div class="summary-item rank" v-if="getIndicatorScore(data.numeratorResult.datas[0][2], key) && getIndicatorScore(data.numeratorResult.datas[0][2], key).rank">
                            <span class="label">排名：</span>
                            <span class="rank-badge">{{ getIndicatorScore(data.numeratorResult.datas[0][2], key).rank }}</span>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>

              <!-- 盈利能力指标组 -->
              <div v-if="hasProfitabilityIndicators(branch.branchData)" class="indicator-group profitability-group">
                <div class="group-header">
                  <h3>💎 盈利能力指标组</h3>
                  <div class="group-header-right">
                    <span class="group-subtitle">2个子指标</span>
                    <span v-if="getProfitabilityGroupScore(branch.orgNo)" class="group-score-badge">
                      汇总得分: {{ getProfitabilityGroupScore(branch.orgNo).totalWeightedScore }}
                    </span>
                  </div>
                </div>
                <div class="group-content">
                  <div 
                    v-for="(data, key) in getProfitabilityIndicators(branch.branchData)" 
                    :key="key"
                    class="indicator-item grouped"
                    :class="{ success: data.success, failed: !data.success }"
                  >
                    <div class="indicator-header compact">
                      <h4>
                        <span class="status-icon">{{ data.success ? '✅' : '❌' }}</span>
                        {{ data.name }}
                      </h4>
                      <span class="indicator-type">{{ getTypeLabel(data) }}</span>
                    </div>
                    
                    <div v-if="data.success" class="indicator-content">
                      <!-- 比率型指标 -->
                      <div v-if="data.type === 'ratio'" class="data-section">
                        <div v-if="data.numeratorResult?.datas && data.denominatorResult?.datas" class="ratio-summary">
                          <div class="summary-item">
                            <span class="label">分子：</span>
                            <span class="value">{{ formatNumber(sumValues(data.numeratorResult.datas)) }}</span>
                          </div>
                          <div class="summary-item">
                            <span class="label">分母：</span>
                            <span class="value">{{ formatNumber(sumValues(data.denominatorResult.datas)) }}</span>
                          </div>
                          <div class="summary-item highlight">
                            <span class="label">{{ key === 'profitPerCapita' ? '人均利润(万元)' : '比率' }}：</span>
                            <span class="value">{{ calculateRatio(data.numeratorResult.datas, data.denominatorResult.datas, key) }}{{ key === 'profitPerCapita' ? '' : '%' }}</span>
                          </div>
                          <div class="summary-item score" v-if="getIndicatorScore(data.numeratorResult.datas[0][2], key)">
                            <span class="label">Z-score评分：</span>
                            <span class="score-badge" :class="getScoreClass(getIndicatorScore(data.numeratorResult.datas[0][2], key).score)">
                              {{ getIndicatorScore(data.numeratorResult.datas[0][2], key).score }}分
                            </span>
                            <span class="z-value">Z: {{ getIndicatorScore(data.numeratorResult.datas[0][2], key).zScore }}</span>
                          </div>
                          <div class="summary-item weight" v-if="getIndicatorScore(data.numeratorResult.datas[0][2], key) && getIndicatorScore(data.numeratorResult.datas[0][2], key).weight">
                            <span class="label">权重：</span>
                            <span class="weight-badge">{{ getIndicatorScore(data.numeratorResult.datas[0][2], key).weight }}%</span>
                            <span class="weighted-score">→ {{ calculateWeightedScore(getIndicatorScore(data.numeratorResult.datas[0][2], key)) }}</span>
                          </div>
                          <div class="summary-item rank" v-if="getIndicatorScore(data.numeratorResult.datas[0][2], key) && getIndicatorScore(data.numeratorResult.datas[0][2], key).rank">
                            <span class="label">排名：</span>
                            <span class="rank-badge">{{ getIndicatorScore(data.numeratorResult.datas[0][2], key).rank }}</span>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>

              <!-- 风险合规指标组 -->
              <div v-if="hasRiskComplianceIndicators(branch.branchData)" class="indicator-group risk-compliance-group">
                <div class="group-header">
                  <h3>⚖️ 风险合规指标组</h3>
                  <div class="group-header-right">
                    <span class="group-subtitle">1个子指标</span>
                    <span v-if="getRiskComplianceGroupScore(branch.orgNo)" class="group-score-badge">
                      汇总得分: {{ getRiskComplianceGroupScore(branch.orgNo).totalWeightedScore }}
                    </span>
                  </div>
                </div>
                <div class="group-content">
                  <div 
                    v-for="(data, key) in getRiskComplianceIndicators(branch.branchData)" 
                    :key="key"
                    class="indicator-item grouped"
                    :class="{ success: data.success, failed: !data.success }"
                  >
                    <div class="indicator-header compact">
                      <h4>
                        <span class="status-icon">{{ data.success ? '✅' : '❌' }}</span>
                        {{ data.name }}
                      </h4>
                      <span class="indicator-type">{{ getTypeLabel(data) }}</span>
                    </div>
                    
                    <div v-if="data.success" class="indicator-content">
                      <!-- 单值型指标 -->
                      <div v-if="data.type === 'single'" class="data-section">
                        <div v-if="data.result?.datas && data.result.datas.length > 0" class="single-summary">
                          <div class="summary-item highlight">
                            <span class="label">得分：</span>
                            <span class="value">{{ formatNumber(parseFloat(data.result.datas[0][3])) }}</span>
                          </div>
                          <div class="summary-item score" v-if="getIndicatorScore(data.result.datas[0][2], key)">
                            <span class="label">Z-score评分：</span>
                            <span class="score-badge" :class="getScoreClass(getIndicatorScore(data.result.datas[0][2], key).score)">
                              {{ getIndicatorScore(data.result.datas[0][2], key).score }}分
                            </span>
                            <span class="z-value">Z: {{ getIndicatorScore(data.result.datas[0][2], key).zScore }}</span>
                          </div>
                          <div class="summary-item weight" v-if="getIndicatorScore(data.result.datas[0][2], key) && getIndicatorScore(data.result.datas[0][2], key).weight">
                            <span class="label">权重：</span>
                            <span class="weight-badge">{{ getIndicatorScore(data.result.datas[0][2], key).weight }}%</span>
                            <span class="weighted-score">→ {{ calculateWeightedScore(getIndicatorScore(data.result.datas[0][2], key)) }}</span>
                          </div>
                          <div class="summary-item rank" v-if="getIndicatorScore(data.result.datas[0][2], key) && getIndicatorScore(data.result.datas[0][2], key).rank">
                            <span class="label">排名：</span>
                            <span class="rank-badge">{{ getIndicatorScore(data.result.datas[0][2], key).rank }}</span>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>

              <!-- 其他指标 -->
              <div 
                v-for="(data, key) in getOtherIndicators(branch.branchData)" 
                :key="key"
                class="indicator-item"
                :class="{ success: data.success, failed: !data.success }"
              >
                <div class="indicator-header">
                  <h4>
                    <span class="status-icon">{{ data.success ? '✅' : '❌' }}</span>
                    {{ data.name }}
                  </h4>
                  <span class="indicator-type">{{ getTypeLabel(data) }}</span>
                </div>
          
          <div v-if="data.success" class="indicator-content">
            <!-- 单值类型 -->
            <div v-if="isSimpleType(data)" class="data-section">
              <div class="data-header">
                <span class="section-title">查询结果</span>
                <span class="record-count">共 {{ data.result?.totalcount || 0 }} 条记录</span>
              </div>
              <div v-if="data.result?.datas && data.result.datas.length > 0" class="data-table">
                <table>
                  <thead>
                    <tr>
                      <th>序号</th>
                      <th v-for="(header, idx) in getTableHeaders(data.result.datas[0])" :key="idx">
                        {{ header }}
                      </th>
                      <th>Z-score评分</th>
                      <th>权重</th>
                      <th>加权得分</th>
                      <th>排名</th>
                    </tr>
                  </thead>
                  <tbody>
                    <tr v-for="(row, rowIdx) in data.result.datas" :key="rowIdx">
                      <td>{{ rowIdx + 1 }}</td>
                      <td v-for="(cell, cellIdx) in row" :key="cellIdx">
                        {{ cell }}
                      </td>
                      <td class="score-cell">
                        <div v-if="getIndicatorScore(row[2], key)" class="score-info">
                          <span class="score-badge" :class="getScoreClass(getIndicatorScore(row[2], key).score)">
                            {{ getIndicatorScore(row[2], key).score }}分
                          </span>
                          <span class="z-value">Z: {{ getIndicatorScore(row[2], key).zScore }}</span>
                        </div>
                        <span v-else class="no-score">-</span>
                      </td>
                      <td class="weight-cell">
                        <span v-if="getIndicatorScore(row[2], key)" class="weight-badge">
                          {{ getIndicatorScore(row[2], key).weight }}%
                        </span>
                        <span v-else class="no-weight">-</span>
                      </td>
                      <td class="weighted-score-cell">
                        <span v-if="getIndicatorScore(row[2], key)" class="weighted-score-value">
                          {{ calculateWeightedScore(getIndicatorScore(row[2], key)) }}
                        </span>
                        <span v-else class="no-weighted-score">-</span>
                      </td>
                      <td class="rank-cell">
                        <span v-if="getIndicatorScore(row[2], key) && getIndicatorScore(row[2], key).rank" class="rank-badge">
                          {{ getIndicatorScore(row[2], key).rank }}
                        </span>
                        <span v-else class="no-rank">-</span>
                      </td>
                    </tr>
                  </tbody>
                </table>
              </div>
              <div v-else class="no-data">无数据</div>
            </div>

            <!-- 比率类型（分子/分母） -->
            <div v-if="data.numeratorResult && data.denominatorResult" class="data-section">
              <!-- 比率计算结果 -->
              <div v-if="data.numeratorResult?.datas && data.denominatorResult?.datas && data.numeratorResult.datas.length > 0" class="ratio-summary">
                <div class="summary-item">
                  <span class="label">分子总和：</span>
                  <span class="value">{{ formatNumber(calculateSum(data.numeratorResult.datas)) }}</span>
                </div>
                <div class="summary-item">
                  <span class="label">分母总和：</span>
                  <span class="value">{{ formatNumber(calculateSum(data.denominatorResult.datas)) }}</span>
                </div>
                <div class="summary-item highlight">
                  <span class="label">{{ key === 'profitPerCapita' ? '人均利润：' : '比率：' }}</span>
                  <span class="value">{{ calculateRatio(data.numeratorResult.datas, data.denominatorResult.datas, key) }}{{ getRatioUnit(key) }}</span>
                </div>
                <div class="summary-item score" v-if="getIndicatorScore(data.numeratorResult.datas[0][2], key)">
                  <span class="label">Z-score评分：</span>
                  <span class="score-badge" :class="getScoreClass(getIndicatorScore(data.numeratorResult.datas[0][2], key).score)">
                    {{ getIndicatorScore(data.numeratorResult.datas[0][2], key).score }}分
                  </span>
                  <span class="z-value">Z: {{ getIndicatorScore(data.numeratorResult.datas[0][2], key).zScore }}</span>
                </div>
                <div class="summary-item weight" v-if="getIndicatorScore(data.numeratorResult.datas[0][2], key) && getIndicatorScore(data.numeratorResult.datas[0][2], key).weight">
                  <span class="label">权重：</span>
                  <span class="weight-badge">{{ getIndicatorScore(data.numeratorResult.datas[0][2], key).weight }}%</span>
                  <span class="weighted-score">→ {{ calculateWeightedScore(getIndicatorScore(data.numeratorResult.datas[0][2], key)) }}</span>
                </div>
                <div class="summary-item rank" v-if="getIndicatorScore(data.numeratorResult.datas[0][2], key) && getIndicatorScore(data.numeratorResult.datas[0][2], key).rank">
                  <span class="label">排名：</span>
                  <span class="rank-badge">{{ getIndicatorScore(data.numeratorResult.datas[0][2], key).rank }}</span>
                </div>
              </div>
              
              <div class="ratio-section">
                <div class="ratio-part">
                  <div class="data-header">
                    <span class="section-title">分子</span>
                    <span class="record-count">共 {{ data.numeratorResult?.totalcount || 0 }} 条记录</span>
                  </div>
                  <div v-if="data.numeratorResult?.datas && data.numeratorResult.datas.length > 0" class="data-table">
                    <table>
                      <thead>
                        <tr>
                          <th>序号</th>
                          <th v-for="(header, idx) in getTableHeaders(data.numeratorResult.datas[0])" :key="idx">
                            {{ header }}
                          </th>
                        </tr>
                      </thead>
                      <tbody>
                        <tr v-for="(row, rowIdx) in data.numeratorResult.datas" :key="rowIdx">
                          <td>{{ rowIdx + 1 }}</td>
                          <td v-for="(cell, cellIdx) in row" :key="cellIdx">
                            {{ cell }}
                          </td>
                        </tr>
                      </tbody>
                    </table>
                  </div>
                  <div v-else class="no-data">无数据</div>
                </div>

                <div class="ratio-divider">÷</div>

                <div class="ratio-part">
                  <div class="data-header">
                    <span class="section-title">分母</span>
                    <span class="record-count">共 {{ data.denominatorResult?.totalcount || 0 }} 条记录</span>
                  </div>
                  <div v-if="data.denominatorResult?.datas && data.denominatorResult.datas.length > 0" class="data-table">
                    <table>
                      <thead>
                        <tr>
                          <th>序号</th>
                          <th v-for="(header, idx) in getTableHeaders(data.denominatorResult.datas[0])" :key="idx">
                            {{ header }}
                          </th>
                        </tr>
                      </thead>
                      <tbody>
                        <tr v-for="(row, rowIdx) in data.denominatorResult.datas" :key="rowIdx">
                          <td>{{ rowIdx + 1 }}</td>
                          <td v-for="(cell, cellIdx) in row" :key="cellIdx">
                            {{ cell }}
                          </td>
                        </tr>
                      </tbody>
                    </table>
                  </div>
                  <div v-else class="no-data">无数据</div>
                </div>
              </div>
            </div>

            <!-- 增长型类型（期初/期末） -->
            <div v-if="data.endResult && data.startResult" class="data-section">
              <div class="growth-header">
                <div class="growth-label">📊 期初期末对比</div>
              </div>
              
              <!-- 增长率计算结果 -->
              <div v-if="data.endResult?.datas && data.startResult?.datas && data.endResult.datas.length > 0 && data.startResult.datas.length > 0" class="growth-summary">
                <div class="summary-item">
                  <span class="label">期初值：</span>
                  <span class="value">{{ formatNumber(parseFloat(data.startResult.datas[0][3])) }}</span>
                </div>
                <div class="summary-item">
                  <span class="label">期末值：</span>
                  <span class="value">{{ formatNumber(parseFloat(data.endResult.datas[0][3])) }}</span>
                </div>
                <div class="summary-item highlight">
                  <span class="label">增长率：</span>
                  <span class="value">{{ calculateGrowthRate(data.endResult.datas[0][3], data.startResult.datas[0][3]) }}%</span>
                </div>
                <div class="summary-item score" v-if="getIndicatorScore(data.endResult.datas[0][2], key)">
                  <span class="label">Z-score评分：</span>
                  <span class="score-badge" :class="getScoreClass(getIndicatorScore(data.endResult.datas[0][2], key).score)">
                    {{ getIndicatorScore(data.endResult.datas[0][2], key).score }}分
                  </span>
                  <span class="z-value">Z: {{ getIndicatorScore(data.endResult.datas[0][2], key).zScore }}</span>
                </div>
                <div class="summary-item weight" v-if="getIndicatorScore(data.endResult.datas[0][2], key) && getIndicatorScore(data.endResult.datas[0][2], key).weight">
                  <span class="label">权重：</span>
                  <span class="weight-badge">{{ getIndicatorScore(data.endResult.datas[0][2], key).weight }}%</span>
                  <span class="weighted-score">→ {{ calculateWeightedScore(getIndicatorScore(data.endResult.datas[0][2], key)) }}</span>
                </div>
                <div class="summary-item rank" v-if="getIndicatorScore(data.endResult.datas[0][2], key) && getIndicatorScore(data.endResult.datas[0][2], key).rank">
                  <span class="label">排名：</span>
                  <span class="rank-badge">{{ getIndicatorScore(data.endResult.datas[0][2], key).rank }}</span>
                </div>
              </div>
              
              <div class="ratio-section">
                <div class="ratio-part">
                  <div class="data-header">
                    <span class="section-title">📅 期初数据（3个月前）</span>
                    <span class="record-count">共 {{ data.startResult?.totalcount || 0 }} 条记录</span>
                  </div>
                  <div v-if="data.startResult?.datas && data.startResult.datas.length > 0" class="data-table">
                    <table>
                      <thead>
                        <tr>
                          <th>序号</th>
                          <th v-for="(header, idx) in getTableHeaders(data.startResult.datas[0])" :key="idx">
                            {{ header }}
                          </th>
                        </tr>
                      </thead>
                      <tbody>
                        <tr v-for="(row, rowIdx) in data.startResult.datas" :key="rowIdx">
                          <td>{{ rowIdx + 1 }}</td>
                          <td v-for="(cell, cellIdx) in row" :key="cellIdx">
                            {{ cell }}
                          </td>
                        </tr>
                      </tbody>
                    </table>
                  </div>
                  <div v-else class="no-data">无数据</div>
                </div>

                <div class="ratio-divider">
                  <div class="arrow">→</div>
                  <div class="arrow-label">增长</div>
                </div>

                <div class="ratio-part">
                  <div class="data-header">
                    <span class="section-title">📅 期末数据（当前）</span>
                    <span class="record-count">共 {{ data.endResult?.totalcount || 0 }} 条记录</span>
                  </div>
                  <div v-if="data.endResult?.datas && data.endResult.datas.length > 0" class="data-table">
                    <table>
                      <thead>
                        <tr>
                          <th>序号</th>
                          <th v-for="(header, idx) in getTableHeaders(data.endResult.datas[0])" :key="idx">
                            {{ header }}
                          </th>
                        </tr>
                      </thead>
                      <tbody>
                        <tr v-for="(row, rowIdx) in data.endResult.datas" :key="rowIdx">
                          <td>{{ rowIdx + 1 }}</td>
                          <td v-for="(cell, cellIdx) in row" :key="cellIdx">
                            {{ cell }}
                          </td>
                        </tr>
                      </tbody>
                    </table>
                  </div>
                  <div v-else class="no-data">无数据</div>
                </div>
              </div>
            </div>

            <!-- 偏离度类型（月末/月均） -->
            <div v-if="data.monthEndResult && data.monthAvgResult" class="data-section">
              <!-- 偏离度计算结果 -->
              <div v-if="data.monthEndResult?.datas && data.monthAvgResult?.datas && data.monthEndResult.datas.length > 0" class="deviation-summary">
                <div class="summary-item">
                  <span class="label">月末余额：</span>
                  <span class="value">{{ formatNumber(parseFloat(data.monthEndResult.datas[0][3])) }}</span>
                </div>
                <div class="summary-item">
                  <span class="label">月日均总和：</span>
                  <span class="value">{{ formatNumber(calculateSum(data.monthAvgResult.datas)) }}</span>
                </div>
                <div class="summary-item highlight">
                  <span class="label">存款偏离度：</span>
                  <span class="value">{{ calculateDeviation(data.monthEndResult.datas[0][3], data.monthAvgResult.datas) }}%</span>
                </div>
                <div class="summary-item score" v-if="getIndicatorScore(data.monthEndResult.datas[0][2], key)">
                  <span class="label">Z-score评分：</span>
                  <span class="score-badge" :class="getScoreClass(getIndicatorScore(data.monthEndResult.datas[0][2], key).score)">
                    {{ getIndicatorScore(data.monthEndResult.datas[0][2], key).score }}分
                  </span>
                  <span class="z-value">Z: {{ getIndicatorScore(data.monthEndResult.datas[0][2], key).zScore }}</span>
                </div>
                <div class="summary-item weight" v-if="getIndicatorScore(data.monthEndResult.datas[0][2], key) && getIndicatorScore(data.monthEndResult.datas[0][2], key).weight">
                  <span class="label">权重：</span>
                  <span class="weight-badge">{{ getIndicatorScore(data.monthEndResult.datas[0][2], key).weight }}%</span>
                  <span class="weighted-score">→ {{ calculateWeightedScore(getIndicatorScore(data.monthEndResult.datas[0][2], key)) }}</span>
                </div>
                <div class="summary-item rank" v-if="getIndicatorScore(data.monthEndResult.datas[0][2], key) && getIndicatorScore(data.monthEndResult.datas[0][2], key).rank">
                  <span class="label">排名：</span>
                  <span class="rank-badge">{{ getIndicatorScore(data.monthEndResult.datas[0][2], key).rank }}</span>
                </div>
              </div>
              
              <div class="ratio-section">
                <div class="ratio-part">
                  <div class="data-header">
                    <span class="section-title">月末余额</span>
                    <span class="record-count">共 {{ data.monthEndResult?.totalcount || 0 }} 条记录</span>
                  </div>
                  <div v-if="data.monthEndResult?.datas && data.monthEndResult.datas.length > 0" class="data-table">
                    <table>
                      <thead>
                        <tr>
                          <th>序号</th>
                          <th v-for="(header, idx) in getTableHeaders(data.monthEndResult.datas[0])" :key="idx">
                            {{ header }}
                          </th>
                        </tr>
                      </thead>
                      <tbody>
                        <tr v-for="(row, rowIdx) in data.monthEndResult.datas" :key="rowIdx">
                          <td>{{ rowIdx + 1 }}</td>
                          <td v-for="(cell, cellIdx) in row" :key="cellIdx">
                            {{ cell }}
                          </td>
                        </tr>
                      </tbody>
                    </table>
                  </div>
                  <div v-else class="no-data">无数据</div>
                </div>

                <div class="ratio-divider">-</div>

                <div class="ratio-part">
                  <div class="data-header">
                    <span class="section-title">月日均余额</span>
                    <span class="record-count">共 {{ data.monthAvgResult?.totalcount || 0 }} 条记录</span>
                  </div>
                  <div v-if="data.monthAvgResult?.datas && data.monthAvgResult.datas.length > 0" class="data-table">
                    <table>
                      <thead>
                        <tr>
                          <th>序号</th>
                          <th v-for="(header, idx) in getTableHeaders(data.monthAvgResult.datas[0])" :key="idx">
                            {{ header }}
                          </th>
                        </tr>
                      </thead>
                      <tbody>
                        <tr v-for="(row, rowIdx) in data.monthAvgResult.datas" :key="rowIdx">
                          <td>{{ rowIdx + 1 }}</td>
                          <td v-for="(cell, cellIdx) in row" :key="cellIdx">
                            {{ cell }}
                          </td>
                        </tr>
                      </tbody>
                    </table>
                  </div>
                  <div v-else class="no-data">无数据</div>
                </div>
              </div>
            </div>
          </div>

          <div v-else class="indicator-error">
            <p>{{ data.error?.message || '获取数据失败' }}</p>
          </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <div v-if="!isLoading && Object.keys(scoreData).length === 0" class="empty-state">
      <p>👆 点击上方按钮开始获取所有支行数据</p>
      <p class="hint">系统将自动获取数据库中所有支行的综合评分指标</p>
    </div>

    <!-- Z-score评分展示 -->
    <ScoreDisplay 
      v-if="!isLoading && Object.keys(scoreData).length > 0" 
      :scoreData="scoreData"
      :indicators="indicators"
    />
  </div>
</template>

<script setup>
import { ref, computed, watch, onMounted } from 'vue'
import { useComprehensiveScore } from '../composables/useComprehensiveScore.js'
import { useScoreCalculation } from '../composables/useScoreCalculation.js'
import ScoreDisplay from './ScoreDisplay.vue'

// 接收共享数据
const props = defineProps({
  sharedData: {
    type: Object,
    default: null
  }
})

const { isLoading, error, scoreData, fetchAllBranchesData, indicators, getOrgName } = useComprehensiveScore()
const { calculateAllScores } = useScoreCalculation()

// 评分结果
const scoreResult = ref(null)

// 表单数据
const bussDate = ref('20250930')

// 如果有共享数据，直接使用
if (props.sharedData) {
  console.log('[综合评分] 使用共享数据')
  scoreData.value = props.sharedData.scoreData
  scoreResult.value = props.sharedData.scoreResult
  bussDate.value = props.sharedData.bussDate
  
  // 默认展开第一个支行
  if (Object.keys(scoreData.value).length > 0) {
    const firstOrgNo = Object.keys(scoreData.value)[0]
    // expandedBranches 会在下面定义
  }
}

// 展开的支行列表
const expandedBranches = ref([])

// 如果使用共享数据，默认展开第一个支行
if (props.sharedData && Object.keys(scoreData.value).length > 0) {
  expandedBranches.value = [Object.keys(scoreData.value)[0]]
}

// 统计数据
const totalBranches = computed(() => Object.keys(scoreData.value).length)

const successBranches = computed(() => {
  return Object.values(scoreData.value).filter(branchData => {
    return !branchData.error && Object.keys(branchData).length > 0
  }).length
})

// 排序后的支行数据（按加权得分从大到小）
const sortedScoreData = computed(() => {
  if (!scoreData.value || !scoreResult.value) return []
  
  // 将对象转为数组，并附加加权得分
  const branchArray = Object.entries(scoreData.value).map(([orgNo, branchData]) => {
    const weightedScore = scoreResult.value?.branches?.[orgNo]?.weightedScore || 0
    return {
      orgNo,
      branchData,
      weightedScore
    }
  })
  
  // 按加权得分从大到小排序
  return branchArray.sort((a, b) => b.weightedScore - a.weightedScore)
})

const failedBranches = computed(() => {
  return Object.values(scoreData.value).filter(branchData => {
    return branchData.error || Object.keys(branchData).length === 0
  }).length
})

// 加载所有支行数据
const loadAllData = async () => {
  expandedBranches.value = [] // 清空展开状态
  await fetchAllBranchesData(bussDate.value)
  // 默认展开第一个支行
  if (Object.keys(scoreData.value).length > 0) {
    expandedBranches.value = [Object.keys(scoreData.value)[0]]
  }
  // 自动计算评分
  calculateScoresIfNeeded()
}

// 页面加载时自动获取数据（仅在独立页面模式，没有共享数据时）
if (!props.sharedData) {
  loadAllData()
}

// 计算评分
const calculateScoresIfNeeded = () => {
  if (Object.keys(scoreData.value).length > 0) {
    try {
      scoreResult.value = calculateAllScores(scoreData.value, indicators)
      console.log('[综合评分测试] 评分计算完成:', scoreResult.value)
    } catch (err) {
      console.error('[综合评分测试] 评分计算失败:', err)
    }
  }
}

// 监听数据变化，自动重新计算
watch(scoreData, () => {
  calculateScoresIfNeeded()
}, { deep: true })

// 执行Excel导出
const performExport = (data) => {
  try {
    const XLSX = window.XLSX
    const wb = XLSX.utils.book_new()
    
    // Sheet 1: 总得分（加权得分）
    const ws1 = XLSX.utils.json_to_sheet(data.weightedScores)
    XLSX.utils.book_append_sheet(wb, ws1, '总得分')
    
    // Sheet 2: 总排名
    const ws2 = XLSX.utils.json_to_sheet(data.rankings)
    XLSX.utils.book_append_sheet(wb, ws2, '总排名')
    
    // Sheet 3: 指标值
    const ws3 = XLSX.utils.json_to_sheet(data.values)
    XLSX.utils.book_append_sheet(wb, ws3, '指标值')
    
    // Sheet 4: Z得分
    const ws4 = XLSX.utils.json_to_sheet(data.zScores)
    XLSX.utils.book_append_sheet(wb, ws4, 'Z得分')
    
    // 生成文件名
    const fileName = `综合评分汇总_${bussDate.value}_${new Date().toISOString().slice(0, 10)}.xlsx`
    XLSX.writeFile(wb, fileName)
    
    console.log(`[导出Excel] 成功导出4个sheet`)
  } catch (err) {
    console.error('[导出Excel] 导出失败:', err)
    alert('导出Excel失败：' + err.message)
  }
}

// 提取指标值的辅助函数
const extractIndicatorValue = (data, key) => {
  // 关注类贷款和迁徙率指标：无数据时返回0
  const concernLoanKeys = ['concernLoanRatio', 'concernLoanBalance', 'concernLoanGrowth']
  const migrationRateKeys = ['normalLoanMigrationRate', 'specialMentionLoanMigrationRate', 'substandardLoanMigrationRate', 'doubtfulLoanMigrationRate']
  const zeroValueKeys = [...concernLoanKeys, ...migrationRateKeys]
  
  if (!data || !data.success) {
    return zeroValueKeys.includes(key) ? '0' : ''
  }
  
  let value = ''
  
  if (data.type === 'single' || data.type === 'multiple') {
    if (data.result?.datas?.[0]?.[3]) {
      value = parseFloat(data.result.datas[0][3]).toFixed(2)
    } else if (zeroValueKeys.includes(key)) {
      // 关注类贷款和迁徙率指标：数据为空时返回0
      value = '0'
    }
  } else if (data.type === 'growth' || data.type === 'increase') {
    if (data.endResult?.datas?.[0]?.[3] && data.startResult?.datas?.[0]?.[3]) {
      const endValue = parseFloat(data.endResult.datas[0][3])
      const startValue = parseFloat(data.startResult.datas[0][3])
      if (data.type === 'growth') {
        value = (((endValue - startValue) / startValue) * 100).toFixed(2)
      } else {
        value = (endValue - startValue).toFixed(2)
      }
    }
  } else if (data.type === 'growthWithWriteOff') {
    if (data.endResult?.datas?.[0]?.[3] && data.startResult?.datas?.[0]?.[3]) {
      const endValue = parseFloat(data.endResult.datas[0][3])
      const startValue = parseFloat(data.startResult.datas[0][3])
      const writeOffValue = (data.writeOffResult?.datas && data.writeOffResult.datas.length > 0)
        ? data.writeOffResult.datas.reduce((sum, row) => sum + parseFloat(row[3] || 0), 0)
        : 0
      value = (((endValue + writeOffValue - startValue) / startValue) * 100).toFixed(2)
    }
  } else if (data.type === 'ratio') {
    if (data.numeratorResult?.datas && data.denominatorResult?.datas) {
      const numerator = data.numeratorResult.datas.reduce((sum, row) => sum + parseFloat(row[3] || 0), 0)
      const denominator = data.denominatorResult.datas.reduce((sum, row) => sum + parseFloat(row[3] || 0), 0)
      if (denominator !== 0) {
        value = ((numerator / denominator) * 100).toFixed(2)
      }
    }
  } else if (data.type === 'deviation') {
    if (data.monthEndResult?.datas?.[0]?.[3] && data.monthAvgResult?.datas) {
      const monthEnd = parseFloat(data.monthEndResult.datas[0][3])
      const monthAvg = data.monthAvgResult.datas.reduce((sum, row) => sum + parseFloat(row[3] || 0), 0)
      if (monthEnd !== 0) {
        value = (((monthEnd - monthAvg) / monthEnd) * 100).toFixed(2)
      }
    }
  }
  
  // 如果仍然没有值，且是需要返回0的指标，返回'0'
  if (!value && zeroValueKeys.includes(key)) {
    return '0'
  }
  
  return value
}

// 导出Excel
const exportToExcel = () => {
  if (!scoreResult.value || Object.keys(scoreData.value).length === 0) {
    alert('没有可导出的数据')
    return
  }

  try {
    // 按加权得分排序的支行列表
    const sortedBranches = Object.entries(scoreResult.value.branches)
      .map(([orgNo, data]) => ({ orgNo, ...data }))
      .sort((a, b) => b.weightedScore - a.weightedScore)
    
    // 获取所有指标的key列表（保持顺序）
    const allIndicatorKeys = []
    const indicatorNames = {}
    
    // 从所有支行收集所有指标（合并去重）
    const indicatorSet = new Set()
    sortedBranches.forEach(branch => {
      const branchData = scoreData.value[branch.orgNo]
      Object.entries(branchData).forEach(([key, data]) => {
        if (data.success && !indicatorSet.has(key)) {
          indicatorSet.add(key)
          allIndicatorKeys.push(key)
          indicatorNames[key] = data.name
        }
      })
    })
    
    
    // Sheet 1: 总得分（加权得分）
    const weightedScores = []
    sortedBranches.forEach((branchScore) => {
      const orgNo = branchScore.orgNo
      const orgName = getOrgName(orgNo)
      const branchData = scoreData.value[orgNo]
      
      const row = {
        '支行编号': orgNo,
        '支行名称': orgName
      }
      
      // 添加每个指标的加权得分
      allIndicatorKeys.forEach(key => {
        const scoreInfo = branchScore.scores[key]
        const weightedScore = scoreInfo?.weightedScore
        // 使用 !== undefined && !== null 来判断，避免0被当作空值
        row[indicatorNames[key]] = (weightedScore !== undefined && weightedScore !== null) ? weightedScore.toFixed(2) : ''
      })
      
      // 添加汇总列
      row['总加权得分'] = branchScore.weightedScore.toFixed(2)
      row['总权重'] = branchScore.totalWeight
      
      weightedScores.push(row)
    })
    
    // Sheet 2: 总排名
    const rankings = []
    sortedBranches.forEach((branchScore) => {
      const orgNo = branchScore.orgNo
      const orgName = getOrgName(orgNo)
      
      const row = {
        '支行编号': orgNo,
        '支行名称': orgName
      }
      
      // 添加每个指标的排名
      allIndicatorKeys.forEach(key => {
        const scoreInfo = branchScore.scores[key]
        row[indicatorNames[key]] = scoreInfo?.rank || ''
      })
      
      // 添加总排名
      row['总排名'] = branchScore.rank
      
      rankings.push(row)
    })
    
    // Sheet 3: 指标值
    const values = []
    sortedBranches.forEach((branchScore) => {
      const orgNo = branchScore.orgNo
      const orgName = getOrgName(orgNo)
      const branchData = scoreData.value[orgNo]
      
      const row = {
        '支行编号': orgNo,
        '支行名称': orgName
      }
      
      // 添加每个指标的值
      allIndicatorKeys.forEach(key => {
        const data = branchData[key]
        row[indicatorNames[key]] = extractIndicatorValue(data, key)
      })
      
      values.push(row)
    })
    
    // Sheet 4: Z得分
    const zScores = []
    sortedBranches.forEach((branchScore) => {
      const orgNo = branchScore.orgNo
      const orgName = getOrgName(orgNo)
      
      const row = {
        '支行编号': orgNo,
        '支行名称': orgName
      }
      
      // 添加每个指标的Z-score
      allIndicatorKeys.forEach(key => {
        const scoreInfo = branchScore.scores[key]
        row[indicatorNames[key]] = scoreInfo?.zScore?.toFixed(4) || ''
      })
      
      zScores.push(row)
    })
    
    // 准备导出数据
    const exportData = {
      weightedScores,
      rankings,
      values,
      zScores
    }
    
    // 使用script标签加载xlsx库（使用本地文件）
    if (!window.XLSX) {
      const script = document.createElement('script')
      // 根据环境选择路径
      if (import.meta.env.PROD) {
        script.src = '/coolv/vfs/root/products/ebi/sys/coolrpt/coolresource/libs/xlsx.full.min.js'
      } else {
        script.src = '/libs/xlsx.full.min.js'
      }
      script.onload = () => {
        performExport(exportData)
      }
      script.onerror = () => {
        console.error('[导出Excel] 加载XLSX库失败')
        alert('导出失败：无法加载Excel库')
      }
      document.head.appendChild(script)
    } else {
      performExport(exportData)
    }
    
  } catch (err) {
    console.error('[导出Excel] 导出失败:', err)
    alert('导出Excel失败：' + err.message)
  }
}

// 切换支行展开/收起
const toggleBranch = (orgNo) => {
  const index = expandedBranches.value.indexOf(orgNo)
  if (index > -1) {
    expandedBranches.value.splice(index, 1)
  } else {
    expandedBranches.value.push(orgNo)
  }
}

// 获取支行成功指标数
const getBranchSuccessCount = (branchData) => {
  if (branchData.error) return 0
  return Object.values(branchData).filter(item => item.success).length
}

// 获取支行失败指标数
const getBranchFailCount = (branchData) => {
  if (branchData.error) return 30
  return Object.values(branchData).filter(item => !item.success).length
}

// 获取类型标签
const getTypeLabel = (data) => {
  if (data.numeratorResult && data.denominatorResult) {
    return '比率型'
  } else if (data.monthEndResult && data.monthAvgResult) {
    return '偏离度型'
  } else if (data.endResult && data.startResult) {
    // 根据 type 区分增长型、增加值型和带核销的增长型
    if (data.type === 'increase') {
      return '增加值型(期初期末对比)'
    } else if (data.type === 'growthWithWriteOff') {
      return '增长型(期初期末+核销)'
    } else {
      return '增长型(期初期末对比)'
    }
  } else if (data.result?.totalcount > 1) {
    return '多值型'
  } else {
    return '单值型'
  }
}

// 判断是否为简单类型
const isSimpleType = (data) => {
  return data.result && !data.numeratorResult && !data.monthEndResult && !data.endResult
}

// 获取表头
const getTableHeaders = (row) => {
  if (!row) return []
  return row.map((_, idx) => {
    const headers = ['业务日期', '指标名称', '机构号', '指标值', '来源表', '其他']
    return headers[idx] || `列${idx + 1}`
  })
}

// 获取指标的Z-score评分
const getIndicatorScore = (orgNo, indicatorKey) => {
  if (!scoreResult.value || !scoreResult.value.branches[orgNo]) {
    return null
  }
  const branchScores = scoreResult.value.branches[orgNo].scores
  if (!branchScores || !branchScores[indicatorKey]) {
    return null
  }
  return branchScores[indicatorKey]
}

// 获取支行排名
const getBranchRank = (orgNo) => {
  if (!scoreResult.value || !scoreResult.value.branches[orgNo]) {
    return null
  }
  return scoreResult.value.branches[orgNo].rank
}

// 获取支行综合得分（加权平均）
const getBranchAverageScore = (orgNo) => {
  if (!scoreResult.value || !scoreResult.value.branches[orgNo]) {
    return null
  }
  return scoreResult.value.branches[orgNo].averageScore
}

// 获取支行加权得分总和
const getBranchWeightedScoreSum = (orgNo) => {
  if (!scoreResult.value || !scoreResult.value.branches[orgNo]) {
    return null
  }
  return scoreResult.value.branches[orgNo].weightedScore
}

// 获取支行总权重
const getBranchTotalWeight = (orgNo) => {
  if (!scoreResult.value || !scoreResult.value.branches[orgNo]) {
    return null
  }
  return scoreResult.value.branches[orgNo].totalWeight
}

// 获取异常指标（Z-score > 1 或 < -1）
const getAbnormalIndicators = (orgNo) => {
  if (!scoreResult.value || !scoreResult.value.branches[orgNo]) {
    return []
  }
  
  const branchScores = scoreResult.value.branches[orgNo].scores
  if (!branchScores) {
    return []
  }
  
  const abnormalList = []
  
  Object.entries(branchScores).forEach(([key, scoreInfo]) => {
    const zScore = scoreInfo.zScore
    const isPositive = scoreInfo.isPositive // 获取指标的正向/负向属性
    
    // 判断是否异常：Z-score > 1 或 < -1
    if (zScore > 1 || zScore < -1) {
      // 根据指标正向/负向属性判断类型：
      // 正向指标：Z-score > 1 表示优秀，Z-score < -1 表示风险
      // 负向指标：Z-score > 1 表示风险，Z-score < -1 表示优秀
      let type, zScoreClass
      if (isPositive) {
        // 正向指标
        type = zScore > 1 ? 'excellent' : 'high-risk'
        zScoreClass = zScore > 1 ? 'zscore-high' : 'zscore-low'
      } else {
        // 负向指标
        type = zScore > 1 ? 'high-risk' : 'excellent'
        zScoreClass = zScore > 1 ? 'zscore-high' : 'zscore-low'
      }
      
      abnormalList.push({
        key: key,
        name: scoreInfo.name,
        value: scoreInfo.originalValue,
        zScore: zScore,
        score: scoreInfo.score,
        type: type,
        zScoreClass: zScoreClass,
        isPositive: isPositive
      })
    }
  })
  
  // 按 Z-score 绝对值排序（从大到小）
  abnormalList.sort((a, b) => Math.abs(b.zScore) - Math.abs(a.zScore))
  
  return abnormalList
}

// 获取得分颜色类
const getScoreClass = (score) => {
  if (score === null || score === undefined) return ''
  if (score >= 90) return 'excellent'
  if (score >= 80) return 'good'
  if (score >= 70) return 'fair'
  if (score >= 60) return 'warning'
  return 'poor'
}

// 计算增长率
const calculateGrowthRate = (endValue, startValue) => {
  const end = parseFloat(endValue)
  const start = parseFloat(startValue)
  if (isNaN(end) || isNaN(start) || start === 0) {
    return '0.00'
  }
  const rate = ((end - start) / start) * 100
  return rate.toFixed(2)
}

// 计算带核销的增长率
const calculateGrowthRateWithWriteOff = (data) => {
  const endValue = parseFloat(data.endResult?.datas?.[0]?.[3] || 0)
  const startValue = parseFloat(data.startResult?.datas?.[0]?.[3] || 0)
  const writeOffValue = (data.writeOffResult?.datas && data.writeOffResult.datas.length > 0)
    ? data.writeOffResult.datas.reduce((sum, row) => sum + parseFloat(row[3] || 0), 0)
    : 0
  
  if (isNaN(endValue) || isNaN(startValue) || startValue === 0) {
    return '0.00'
  }
  const rate = ((endValue + writeOffValue - startValue) / startValue) * 100
  return rate.toFixed(2)
}

// 格式化数字
const formatNumber = (num) => {
  if (isNaN(num)) return '0'
  // 如果数字很大，使用千分位分隔
  if (Math.abs(num) >= 1000) {
    return num.toLocaleString('zh-CN', { maximumFractionDigits: 2 })
  }
  return num.toFixed(2)
}

// 计算数据行的总和
const calculateSum = (datas) => {
  if (!datas || datas.length === 0) return 0
  return datas.reduce((sum, row) => {
    return sum + parseFloat(row[3] || 0)
  }, 0)
}

// 求和数值（别名，用于模板）
const sumValues = (datas) => {
  return calculateSum(datas)
}

// 计算偏离度
const calculateDeviation = (monthEnd, monthAvgDatas) => {
  const monthEndValue = parseFloat(monthEnd)
  const monthAvgSum = calculateSum(monthAvgDatas)
  if (monthEndValue === 0) return '0.00'
  const deviation = ((monthEndValue - monthAvgSum) / monthEndValue) * 100
  return deviation.toFixed(2)
}

// 计算比率
const calculateRatio = (numeratorDatas, denominatorDatas, key) => {
  const numerator = calculateSum(numeratorDatas)
  const denominator = calculateSum(denominatorDatas)
  if (denominator === 0) return '0.00'
  
  // 人均利润：单位为万元
  if (key === 'profitPerCapita') {
    const wanYuan = (numerator / denominator) / 10000
    return wanYuan.toFixed(2)
  }
  
  // 其他比率型指标：单位为百分比
  const ratio = (numerator / denominator) * 100
  return ratio.toFixed(2)
}

// 获取比率单位
const getRatioUnit = (key) => {
  if (key === 'profitPerCapita') {
    return '万元'
  }
  return '%'
}

// 计算加权得分（Z-score得分 × 权重/100）
const calculateWeightedScore = (scoreInfo) => {
  if (!scoreInfo || scoreInfo.score === null || scoreInfo.score === undefined || !scoreInfo.weight) {
    return '-'
  }
  // 权重是百分比，需要除以100
  const weightedScore = (scoreInfo.score * scoreInfo.weight / 100).toFixed(2)
  return weightedScore
}

// 不良贷款指标的key列表
const badLoanKeys = [
  'badLoanRate',
  'badLoanBalance',
  'badLoanGrowth'
]

// 关注类贷款指标的key列表
const concernLoanKeys = [
  'concernLoanBalance',  // 关注类贷款余额
  'concernLoanGrowth',  // 关注类贷款增幅
  'concernLoanRatio'  // 关注类贷款占比
]

// 检查是否有关注类贷款指标
const hasConcernLoanIndicators = (branchData) => {
  return concernLoanKeys.some(key => branchData[key])
}

// 获取关注类贷款指标
const getConcernLoanIndicators = (branchData) => {
  const indicators = {}
  const indicatorNames = {
    concernLoanBalance: '关注类贷款余额',
    concernLoanGrowth: '关注类贷款增幅',
    concernLoanRatio: '关注类贷款占比'
  }
  
  concernLoanKeys.forEach(key => {
    if (branchData[key]) {
      indicators[key] = branchData[key]
    } else {
      // 如果不存在，创建一个默认的0值对象
      const isGrowthType = key === 'concernLoanGrowth'
      if (isGrowthType) {
        // 增长型指标
        indicators[key] = {
          key,
          name: indicatorNames[key],
          type: 'growth',
          success: true,
          endResult: {
            isselect: true,
            totalcount: 1,
            pageIndex: 0,
            datas: [[null, null, null, '0']]
          },
          startResult: {
            isselect: true,
            totalcount: 1,
            pageIndex: 0,
            datas: [[null, null, null, '0']]
          }
        }
      } else {
        // 单值型指标
        indicators[key] = {
          key,
          name: indicatorNames[key],
          type: 'single',
          success: true,
          result: {
            isselect: true,
            totalcount: 1,
            pageIndex: 0,
            datas: [[null, null, null, '0']]
          }
        }
      }
    }
  })
  return indicators
}

// 计算关注类贷款指标组的汇总加权得分
const getConcernLoanGroupScore = (orgNo) => {
  if (!scoreData.value || !scoreData.value[orgNo]) return null
  
  let totalWeightedScore = 0
  let totalWeight = 0
  let successCount = 0
  
  concernLoanKeys.forEach(key => {
    const indicatorData = scoreData.value[orgNo][key]
    if (!indicatorData || !indicatorData.success) return
    
    // 获取评分信息
    let scoreInfo = null
    if (indicatorData.result?.datas?.[0]) {
      scoreInfo = getIndicatorScore(indicatorData.result.datas[0][2], key)
    } else if (indicatorData.endResult?.datas?.[0]) {
      scoreInfo = getIndicatorScore(indicatorData.endResult.datas[0][2], key)
    }
    
    if (scoreInfo && scoreInfo.score && scoreInfo.weight) {
      const weightedScore = scoreInfo.score * scoreInfo.weight / 100
      totalWeightedScore += weightedScore
      totalWeight += scoreInfo.weight
      successCount++
    }
  })
  
  return {
    totalWeightedScore: totalWeightedScore.toFixed(2),
    totalWeight,
    successCount,
    totalCount: concernLoanKeys.length
  }
}

// 检查是否有不良贷款指标
const hasBadLoanIndicators = (branchData) => {
  return badLoanKeys.some(key => branchData[key])
}

// 获取不良贷款指标
const getBadLoanIndicators = (branchData) => {
  const indicators = {}
  badLoanKeys.forEach(key => {
    if (branchData[key]) {
      indicators[key] = branchData[key]
    }
  })
  return indicators
}

// 计算不良贷款指标组的汇总加权得分
const getBadLoanGroupScore = (orgNo) => {
  if (!scoreData.value || !scoreData.value[orgNo]) return null
  
  let totalWeightedScore = 0
  let totalWeight = 0
  let successCount = 0
  
  badLoanKeys.forEach(key => {
    const indicatorData = scoreData.value[orgNo][key]
    if (!indicatorData || !indicatorData.success) return
    
    // 获取评分信息
    let scoreInfo = null
    if (indicatorData.result?.datas?.[0]) {
      scoreInfo = getIndicatorScore(indicatorData.result.datas[0][2], key)
    } else if (indicatorData.endResult?.datas?.[0]) {
      scoreInfo = getIndicatorScore(indicatorData.endResult.datas[0][2], key)
    }
    
    if (scoreInfo && scoreInfo.score && scoreInfo.weight) {
      const weightedScore = scoreInfo.score * scoreInfo.weight / 100
      totalWeightedScore += weightedScore
      totalWeight += scoreInfo.weight
      successCount++
    }
  })
  
  return {
    totalWeightedScore: totalWeightedScore.toFixed(2),
    totalWeight,
    successCount,
    totalCount: badLoanKeys.length
  }
}

// 贷款迁徙率指标的key列表
const loanMigrationRateKeys = [
  'normalLoanMigrationRate',
  'specialMentionLoanMigrationRate',  // 关注类贷款迁徙率
  'substandardLoanMigrationRate',
  'doubtfulLoanMigrationRate'
]

// 检查是否有贷款迁徙率指标
const hasLoanMigrationRates = (branchData) => {
  return loanMigrationRateKeys.some(key => branchData[key])
}

// 计算贷款迁徙率指标组的汇总加权得分
const getLoanMigrationGroupScore = (orgNo) => {
  if (!scoreData.value || !scoreData.value[orgNo]) return null
  
  let totalWeightedScore = 0
  let totalWeight = 0
  let successCount = 0
  
  loanMigrationRateKeys.forEach(key => {
    const indicatorData = scoreData.value[orgNo][key]
    if (!indicatorData || !indicatorData.success) return
    
    // 获取评分信息
    let scoreInfo = null
    if (indicatorData.result?.datas?.[0]) {
      scoreInfo = getIndicatorScore(indicatorData.result.datas[0][2], key)
    }
    
    if (scoreInfo && scoreInfo.score && scoreInfo.weight) {
      const weightedScore = scoreInfo.score * scoreInfo.weight / 100
      totalWeightedScore += weightedScore
      totalWeight += scoreInfo.weight
      successCount++
    }
  })
  
  return {
    totalWeightedScore: totalWeightedScore.toFixed(2),
    totalWeight,
    successCount,
    totalCount: loanMigrationRateKeys.length
  }
}

// 获取贷款迁徙率指标
const getLoanMigrationRates = (branchData) => {
  const rates = {}
  const indicatorNames = {
    normalLoanMigrationRate: '正常类贷款迁徙率',
    specialMentionLoanMigrationRate: '关注类贷款迁徙率',
    substandardLoanMigrationRate: '次级类贷款迁徙率',
    doubtfulLoanMigrationRate: '可疑类贷款迁徙率'
  }
  
  loanMigrationRateKeys.forEach(key => {
    if (branchData[key]) {
      rates[key] = branchData[key]
    } else {
      // 如果不存在，创建一个默认的0值对象
      rates[key] = {
        key,
        name: indicatorNames[key],
        type: 'single',
        success: true,
        result: {
          isselect: true,
          totalcount: 1,
          pageIndex: 0,
          datas: [[null, null, null, '0']]  // 创建一个值为0的数据行
        }
      }
    }
  })
  return rates
}

// 贷款集中度指标的key列表
const loanConcentrationKeys = [
  'top10LoanRatio',     // Top10客户贷款占比
  'top10LoanBalance'    // Top10客户贷款余额
]

// 检查是否有贷款集中度指标
const hasLoanConcentrationIndicators = (branchData) => {
  return loanConcentrationKeys.some(key => branchData[key])
}

// 获取贷款集中度指标
const getLoanConcentrationIndicators = (branchData) => {
  const indicators = {}
  loanConcentrationKeys.forEach(key => {
    if (branchData[key]) {
      indicators[key] = branchData[key]
    }
  })
  return indicators
}

// 计算贷款集中度指标组的汇总加权得分
const getLoanConcentrationGroupScore = (orgNo) => {
  if (!scoreData.value || !scoreData.value[orgNo]) return null
  
  let totalWeightedScore = 0
  let totalWeight = 0
  let successCount = 0
  
  loanConcentrationKeys.forEach(key => {
    const indicatorData = scoreData.value[orgNo][key]
    if (!indicatorData || !indicatorData.success) return
    
    // 获取评分信息
    let scoreInfo = null
    if (indicatorData.result?.datas?.[0]) {
      scoreInfo = getIndicatorScore(indicatorData.result.datas[0][2], key)
    }
    
    if (scoreInfo && scoreInfo.score && scoreInfo.weight) {
      const weightedScore = scoreInfo.score * scoreInfo.weight / 100
      totalWeightedScore += weightedScore
      totalWeight += scoreInfo.weight
      successCount++
    }
  })
  
  return {
    totalWeightedScore: totalWeightedScore.toFixed(2),
    totalWeight,
    successCount,
    totalCount: loanConcentrationKeys.length
  }
}

// 存款业务指标的key列表
const depositKeys = [
  'depositGrowth',        // 存款余额增速
  'depositIncrease',      // 存款余额增加值
  'lowCostDepositRatio',  // 低成本存款占比
  'depositDeviation'      // 存款偏离度
]

// 检查是否有存款业务指标
const hasDepositIndicators = (branchData) => {
  return depositKeys.some(key => branchData[key])
}

// 获取存款业务指标
const getDepositIndicators = (branchData) => {
  const indicators = {}
  depositKeys.forEach(key => {
    if (branchData[key]) {
      indicators[key] = branchData[key]
    }
  })
  return indicators
}

// 计算存款业务指标组的汇总加权得分
const getDepositGroupScore = (orgNo) => {
  if (!scoreData.value || !scoreData.value[orgNo]) return null
  
  let totalWeightedScore = 0
  let totalWeight = 0
  let successCount = 0
  
  depositKeys.forEach(key => {
    const indicatorData = scoreData.value[orgNo][key]
    if (!indicatorData || !indicatorData.success) return
    
    // 获取评分信息
    let scoreInfo = null
    if (indicatorData.type === 'growth' && indicatorData.endResult?.datas?.[0]) {
      scoreInfo = getIndicatorScore(indicatorData.endResult.datas[0][2], key)
    } else if (indicatorData.type === 'ratio' && indicatorData.numeratorResult?.datas?.[0]) {
      scoreInfo = getIndicatorScore(indicatorData.numeratorResult.datas[0][2], key)
    } else if (indicatorData.type === 'deviation' && indicatorData.monthEndResult?.datas?.[0]) {
      scoreInfo = getIndicatorScore(indicatorData.monthEndResult.datas[0][2], key)
    }
    
    if (scoreInfo && scoreInfo.score && scoreInfo.weight) {
      const weightedScore = scoreInfo.score * scoreInfo.weight / 100
      totalWeightedScore += weightedScore
      totalWeight += scoreInfo.weight
      successCount++
    }
  })
  
  return {
    totalWeightedScore: totalWeightedScore.toFixed(2),
    totalWeight,
    successCount,
    totalCount: depositKeys.length
  }
}

// 贷款业务指标的key列表
const loanKeys = [
  'newLoanAmount',        // 新增贷款投放额
  'totalLoan',            // 各项贷款
  'loanAccountIncrease',  // 贷款户数增加值
  'loanAccountGrowth'     // 贷款户数增长率
]

// 检查是否有贷款业务指标
const hasLoanIndicators = (branchData) => {
  return loanKeys.some(key => branchData[key])
}

// 获取贷款业务指标
const getLoanIndicators = (branchData) => {
  const indicators = {}
  loanKeys.forEach(key => {
    if (branchData[key]) {
      indicators[key] = branchData[key]
    }
  })
  return indicators
}

// 计算贷款业务指标组的汇总加权得分
const getLoanGroupScore = (orgNo) => {
  if (!scoreData.value || !scoreData.value[orgNo]) return null
  
  let totalWeightedScore = 0
  let totalWeight = 0
  let successCount = 0
  
  loanKeys.forEach(key => {
    const indicatorData = scoreData.value[orgNo][key]
    if (!indicatorData || !indicatorData.success) return
    
    // 获取评分信息 (growth 和 increase 类型都从 endResult 中获取)
    let scoreInfo = null
    if ((indicatorData.type === 'growth' || indicatorData.type === 'increase') && indicatorData.endResult?.datas?.[0]) {
      scoreInfo = getIndicatorScore(indicatorData.endResult.datas[0][2], key)
    }
    
    if (scoreInfo && scoreInfo.score && scoreInfo.weight) {
      const weightedScore = scoreInfo.score * scoreInfo.weight / 100
      totalWeightedScore += weightedScore
      totalWeight += scoreInfo.weight
      successCount++
    }
  })
  
  return {
    totalWeightedScore: totalWeightedScore.toFixed(2),
    totalWeight,
    successCount,
    totalCount: loanKeys.length
  }
}

// 中间业务指标的key列表
const intermediateIncomeKeys = [
  'intermediateIncomeAmount',  // 中间业务收入绝对额
  'intermediateIncomeRatio',   // 中间业务收入占比
  'intermediateIncomeGrowth',  // 中间业务收入增长率
  'stableIncomeRatio',         // 稳定型中收占比
  'stableIncomeAmount',        // 稳定型中收绝对额
  'stableIncomeGrowth'         // 稳定型中收增长率
]

// 检查是否有中间业务指标
const hasIntermediateIncomeIndicators = (branchData) => {
  return intermediateIncomeKeys.some(key => branchData[key])
}

// 获取中间业务指标
const getIntermediateIncomeIndicators = (branchData) => {
  const indicators = {}
  intermediateIncomeKeys.forEach(key => {
    if (branchData[key]) {
      indicators[key] = branchData[key]
    }
  })
  return indicators
}

// 计算中间业务指标组的汇总加权得分
const getIntermediateIncomeGroupScore = (orgNo) => {
  if (!scoreData.value || !scoreData.value[orgNo]) return null
  
  let totalWeightedScore = 0
  let totalWeight = 0
  let successCount = 0
  
  intermediateIncomeKeys.forEach(key => {
    const indicatorData = scoreData.value[orgNo][key]
    if (!indicatorData || !indicatorData.success) return
    
    // 获取评分信息
    let scoreInfo = null
    if ((indicatorData.type === 'growth' || indicatorData.type === 'increase') && indicatorData.endResult?.datas?.[0]) {
      scoreInfo = getIndicatorScore(indicatorData.endResult.datas[0][2], key)
    } else if (indicatorData.type === 'ratio' && indicatorData.numeratorResult?.datas?.[0]) {
      scoreInfo = getIndicatorScore(indicatorData.numeratorResult.datas[0][2], key)
    }
    
    if (scoreInfo && scoreInfo.score && scoreInfo.weight) {
      const weightedScore = scoreInfo.score * scoreInfo.weight / 100
      totalWeightedScore += weightedScore
      totalWeight += scoreInfo.weight
      successCount++
    }
  })
  
  return {
    totalWeightedScore: totalWeightedScore.toFixed(2),
    totalWeight,
    successCount,
    totalCount: intermediateIncomeKeys.length
  }
}

// 计算增长率（多条记录求和后计算）
const calculateGrowthRateFromSum = (endDatas, startDatas) => {
  const endSum = sumValues(endDatas)
  const startSum = sumValues(startDatas)
  if (startSum === 0) return '0.00'
  return (((endSum - startSum) / startSum) * 100).toFixed(2)
}

// 盈利能力指标的key列表
const profitabilityKeys = [
  'profitPerCapita',   // 人均利润
  'costIncomeRatio'    // 成本收入比
]

// 检查是否有盈利能力指标
const hasProfitabilityIndicators = (branchData) => {
  return profitabilityKeys.some(key => branchData[key])
}

// 获取盈利能力指标
const getProfitabilityIndicators = (branchData) => {
  const indicators = {}
  profitabilityKeys.forEach(key => {
    if (branchData[key]) {
      indicators[key] = branchData[key]
    }
  })
  return indicators
}

// 计算盈利能力指标组的汇总加权得分
const getProfitabilityGroupScore = (orgNo) => {
  if (!scoreData.value || !scoreData.value[orgNo]) return null
  
  let totalWeightedScore = 0
  let totalWeight = 0
  let successCount = 0
  
  profitabilityKeys.forEach(key => {
    const indicatorData = scoreData.value[orgNo][key]
    if (!indicatorData || !indicatorData.success) return
    
    // 获取评分信息（比率型指标从 numeratorResult 中获取）
    let scoreInfo = null
    if (indicatorData.type === 'ratio' && indicatorData.numeratorResult?.datas?.[0]) {
      scoreInfo = getIndicatorScore(indicatorData.numeratorResult.datas[0][2], key)
    }
    
    if (scoreInfo && scoreInfo.score && scoreInfo.weight) {
      const weightedScore = scoreInfo.score * scoreInfo.weight / 100
      totalWeightedScore += weightedScore
      totalWeight += scoreInfo.weight
      successCount++
    }
  })
  
  return {
    totalWeightedScore: totalWeightedScore.toFixed(2),
    totalWeight,
    successCount,
    totalCount: profitabilityKeys.length
  }
}

// 风险合规指标的key列表
const riskComplianceKeys = [
  'riskComplianceScore'   // 风险合规得分
]

// 检查是否有风险合规指标
const hasRiskComplianceIndicators = (branchData) => {
  return riskComplianceKeys.some(key => branchData[key])
}

// 获取风险合规指标
const getRiskComplianceIndicators = (branchData) => {
  const indicators = {}
  riskComplianceKeys.forEach(key => {
    if (branchData[key]) {
      indicators[key] = branchData[key]
    }
  })
  return indicators
}

// 计算风险合规指标组的汇总加权得分
const getRiskComplianceGroupScore = (orgNo) => {
  if (!scoreData.value || !scoreData.value[orgNo]) return null
  
  let totalWeightedScore = 0
  let totalWeight = 0
  let successCount = 0
  
  riskComplianceKeys.forEach(key => {
    const indicatorData = scoreData.value[orgNo][key]
    if (!indicatorData || !indicatorData.success) return
    
    // 获取评分信息（单值型指标从 result 中获取）
    let scoreInfo = null
    if (indicatorData.type === 'single' && indicatorData.result?.datas?.[0]) {
      scoreInfo = getIndicatorScore(indicatorData.result.datas[0][2], key)
    }
    
    if (scoreInfo && scoreInfo.score && scoreInfo.weight) {
      const weightedScore = scoreInfo.score * scoreInfo.weight / 100
      totalWeightedScore += weightedScore
      totalWeight += scoreInfo.weight
      successCount++
    }
  })
  
  return {
    totalWeightedScore: totalWeightedScore.toFixed(2),
    totalWeight,
    successCount,
    totalCount: riskComplianceKeys.length
  }
}

// 获取其他指标（排除不良贷款、关注类贷款、贷款迁徙率、贷款集中度、存款业务、贷款业务、中间业务、盈利能力和风险合规）
const getOtherIndicators = (branchData) => {
  const others = {}
  Object.entries(branchData).forEach(([key, data]) => {
    if (!badLoanKeys.includes(key) && 
        !concernLoanKeys.includes(key) && 
        !loanMigrationRateKeys.includes(key) &&
        !loanConcentrationKeys.includes(key) &&
        !depositKeys.includes(key) &&
        !loanKeys.includes(key) &&
        !intermediateIncomeKeys.includes(key) &&
        !profitabilityKeys.includes(key) &&
        !riskComplianceKeys.includes(key)) {
      others[key] = data
    }
  })
  return others
}
</script>

<style scoped>
.comprehensive-score-test {
  padding: 20px;
  max-width: 1400px;
  margin: 0 auto;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 
    'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  color: #1a1a1a;
}

.comprehensive-score-test h1,
.comprehensive-score-test h2,
.comprehensive-score-test h3,
.comprehensive-score-test h4,
.comprehensive-score-test h5,
.comprehensive-score-test p,
.comprehensive-score-test span,
.comprehensive-score-test div {
  color: inherit;
}

.comprehensive-score-test .branch-header > h3,
.comprehensive-score-test .branch-header > h3 *,
.comprehensive-score-test .branch-header > .branch-stats,
.comprehensive-score-test .branch-header > .branch-stats * {
  color: white !important;
}

/* 确保“异常指标”块在标题区域内也使用高对比颜色 */
.comprehensive-score-test .branch-header .abnormal-indicators { color: #262626 !important; }
.comprehensive-score-test .branch-header .abnormal-indicators * { color: inherit; }
.comprehensive-score-test .branch-header .abnormal-title { color: #ff4d4f !important; }
.comprehensive-score-test .branch-header .abnormal-item { color: #262626 !important; }
.comprehensive-score-test .branch-header .abnormal-item .indicator-name { color: #262626 !important; }
.comprehensive-score-test .branch-header .abnormal-item .indicator-value { color: #595959 !important; }
.comprehensive-score-test .branch-header .abnormal-item .indicator-zscore { font-weight: 700; }
.comprehensive-score-test .branch-header .abnormal-item .indicator-zscore.zscore-high { background: #fff2f0 !important; color: #ff4d4f !important; }
.comprehensive-score-test .branch-header .abnormal-item .indicator-zscore.zscore-low { background: #f6ffed !important; color: #52c41a !important; }

.test-header {
  margin-bottom: 30px;
  text-align: center;
}

.test-header h2 {
  font-size: 28px;
  color: #1a1a1a;
  margin-bottom: 10px;
}

.subtitle {
  color: #666;
  font-size: 14px;
}

.test-controls {
  background: white;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  margin-bottom: 30px;
  display: flex;
  gap: 20px;
  align-items: center;
  flex-wrap: wrap;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.control-group label {
  font-weight: 500;
  color: #333;
}

.control-group input {
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
  width: 150px;
}

.control-group input:focus {
  outline: none;
  border-color: #1890ff;
}

.btn-load {
  padding: 10px 24px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s;
}

.btn-load:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-load:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-export {
  padding: 10px 24px;
  background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s;
  margin-left: 12px;
}

.dialog-export {
  display: flex;
  justify-content: flex-end;
  padding: 16px 20px;
  background: rgba(255, 255, 255, 0.05);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 20px;
}

.dialog-export .btn-export {
  margin-left: 0;
}

.btn-export:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(17, 153, 142, 0.4);
}

.btn-export:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  background: #ccc;
}

.loading {
  text-align: center;
  padding: 60px 20px;
}

.spinner {
  width: 50px;
  height: 50px;
  border: 4px solid #f3f3f3;
  border-top: 4px solid #667eea;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 20px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.error-message {
  background: #fff2f0;
  border: 1px solid #ffccc7;
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
}

.error-message h3 {
  color: #cf1322;
  margin-bottom: 10px;
}

.error-message p {
  color: #cf1322;
  margin: 0;
}

.results {
  background: white;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.results h3 {
  font-size: 20px;
  margin-bottom: 20px;
  color: #1a1a1a;
}

.summary {
  display: flex;
  gap: 20px;
  margin-bottom: 30px;
  padding: 15px;
  background: #f5f5f5;
  border-radius: 6px;
}

.summary-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: white;
  border-radius: 4px;
  font-size: 16px;
}

.summary-item .label {
  color: #666;
}

.summary-item .value {
  font-weight: bold;
  font-size: 20px;
}

.summary-item.success .value {
  color: #52c41a;
}

.summary-item.error .value {
  color: #ff4d4f;
}

.indicator-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* 指标组样式 */
.indicator-group {
  border: 3px solid #1890ff;
  border-radius: 12px;
  background: linear-gradient(135deg, #e6f7ff 0%, #f0f7ff 100%);
  padding: 20px;
  margin-bottom: 20px;
}

/* 关注类贷款指标组特殊样式 */
.indicator-group.concern-loan-group {
  border-color: #faad14;
  background: linear-gradient(135deg, #fffbe6 0%, #fff7e6 100%);
}

.indicator-group.concern-loan-group .group-header {
  border-bottom-color: #faad14;
}

.indicator-group.concern-loan-group .group-header h3 {
  color: #faad14;
}

.group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  padding-bottom: 15px;
  border-bottom: 2px solid #1890ff;
}

.group-header h3 {
  margin: 0;
  font-size: 20px;
  color: #1890ff;
  font-weight: bold;
}

.group-header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.group-subtitle {
  font-size: 14px;
  color: #666;
  background: white;
  padding: 4px 12px;
  border-radius: 12px;
  border: 1px solid #d9d9d9;
}

.group-score-badge {
  font-size: 16px;
  font-weight: bold;
  color: #fa8c16;
  background: linear-gradient(135deg, #fff7e6 0%, #fffbe6 100%);
  padding: 8px 16px;
  border-radius: 12px;
  border: 2px solid #ffa940;
  box-shadow: 0 2px 8px rgba(255, 169, 64, 0.3);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

.group-content {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(450px, 1fr));
  gap: 15px;
}

.indicator-item.grouped {
  background: white;
  border: 2px solid #d9d9d9;
  border-radius: 8px;
  padding: 15px;
  transition: all 0.3s;
}

.indicator-item.grouped:hover {
  border-color: #1890ff;
  box-shadow: 0 4px 12px rgba(24, 144, 255, 0.2);
  transform: translateY(-2px);
}

.indicator-item.grouped.success {
  border-color: #b7eb8f;
}

.indicator-header.compact {
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 1px solid #e8e8e8;
}

.indicator-header.compact h4 {
  font-size: 16px;
}

.data-section.compact {
  margin: 0;
}

/* 贷款迁徙率显示样式 */
.migration-rate-display {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px;
  background: #fafafa;
  border-radius: 6px;
}

.migration-rate-display > div {
  display: flex;
  align-items: center;
  gap: 10px;
}

.migration-rate-display .label {
  color: #666;
  font-weight: 500;
  font-size: 13px;
  min-width: 90px;
}

.migration-rate-display .value {
  color: #333;
  font-weight: 600;
  font-size: 15px;
  font-family: monospace;
}

.migration-rate-display .rate-value {
  padding: 8px;
  background: white;
  border-radius: 4px;
  border-left: 3px solid #1890ff;
}

.migration-rate-display .rate-score {
  padding: 8px;
  background: #f6ffed;
  border-radius: 4px;
  border-left: 3px solid #52c41a;
}

.migration-rate-display .rate-weight {
  padding: 8px;
  background: #e6f7ff;
  border-radius: 4px;
  border-left: 3px solid #1890ff;
}

.migration-rate-display .rate-rank {
  padding: 8px;
  background: #fffbe6;
  border-radius: 4px;
  border-left: 3px solid #faad14;
}

.indicator-item {
  border: 2px solid #e8e8e8;
  border-radius: 8px;
  padding: 20px;
  transition: all 0.3s;
}

.indicator-item.success {
  border-color: #b7eb8f;
  background: #f6ffed;
}

.indicator-item.failed {
  border-color: #ffccc7;
  background: #fff2f0;
}

.indicator-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  padding-bottom: 15px;
  border-bottom: 1px solid #e8e8e8;
}

.indicator-header h4 {
  font-size: 18px;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-icon {
  font-size: 20px;
}

.indicator-type {
  padding: 4px 12px;
  background: #f0f0f0;
  border-radius: 12px;
  font-size: 12px;
  color: #666;
}

.indicator-content {
  margin-top: 15px;
}

.data-section {
  margin-bottom: 15px;
}

.data-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.section-title {
  font-weight: 600;
  color: #333;
}

.record-count {
  font-size: 12px;
  color: #999;
}

.data-table {
  overflow-x: auto;
}

.data-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th,
.data-table td {
  padding: 8px 12px;
  text-align: left;
  border: 1px solid #e8e8e8;
}

.data-table th {
  background: #fafafa;
  font-weight: 600;
  color: #333;
}

.data-table td {
  color: #666;
}

.data-table tr:hover td {
  background: #f5f5f5;
}

.no-data {
  padding: 20px;
  text-align: center;
  color: #999;
  background: #fafafa;
  border-radius: 4px;
}

.ratio-section {
  display: flex;
  gap: 15px;
  align-items: flex-start;
  overflow-x: auto;
}

.ratio-part {
  flex: 1;
  min-width: 400px;
  max-width: 600px;
}

.ratio-divider {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px 10px;
  flex-shrink: 0;
}

.ratio-divider .arrow {
  font-size: 32px;
  font-weight: bold;
  color: #52c41a;
}

.ratio-divider .arrow-label {
  font-size: 12px;
  color: #999;
  margin-top: 5px;
}

.growth-header {
  margin-bottom: 15px;
  padding: 10px 15px;
  background: #e6f7ff;
  border-left: 4px solid #1890ff;
  border-radius: 4px;
}

.growth-label {
  font-size: 14px;
  font-weight: 600;
  color: #1890ff;
}

/* 增长率摘要 */
.growth-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
  padding: 15px;
  background: #f0f7ff;
  border-radius: 8px;
  margin-bottom: 15px;
  border-left: 4px solid #1890ff;
}

/* 比率摘要 */
.ratio-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
  padding: 15px;
  background: #f9f0ff;
  border-radius: 8px;
  margin-bottom: 15px;
  border-left: 4px solid #722ed1;
}

/* 偏离度摘要 */
.deviation-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
  padding: 15px;
  background: #fff7e6;
  border-radius: 8px;
  margin-bottom: 15px;
  border-left: 4px solid #fa8c16;
}

.growth-summary .summary-item,
.ratio-summary .summary-item,
.deviation-summary .summary-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 15px;
  background: white;
  border-radius: 6px;
  font-size: 14px;
}

.growth-summary .summary-item .label,
.ratio-summary .summary-item .label,
.deviation-summary .summary-item .label {
  color: #666;
  font-weight: 500;
}

.growth-summary .summary-item .value,
.ratio-summary .summary-item .value,
.deviation-summary .summary-item .value {
  color: #333;
  font-weight: 600;
  font-size: 15px;
}

.growth-summary .summary-item.highlight,
.ratio-summary .summary-item.highlight,
.deviation-summary .summary-item.highlight {
  background: linear-gradient(135deg, #fff9e6 0%, #fff4d9 100%);
  border: 2px solid #faad14;
}

.growth-summary .summary-item.highlight .value,
.ratio-summary .summary-item.highlight .value,
.deviation-summary .summary-item.highlight .value {
  color: #d48806;
  font-size: 16px;
  font-weight: bold;
}

.growth-summary .summary-item.score,
.ratio-summary .summary-item.score,
.deviation-summary .summary-item.score {
  background: #f6ffed;
  border: 1px solid #b7eb8f;
}

.growth-summary .summary-item.weight,
.ratio-summary .summary-item.weight,
.deviation-summary .summary-item.weight {
  background: #e6f7ff;
  border: 1px solid #91d5ff;
}

.growth-summary .summary-item.rank,
.ratio-summary .summary-item.rank,
.deviation-summary .summary-item.rank {
  background: #fffbe6;
  border: 1px solid #ffe58f;
}

.growth-summary .summary-item .score-badge,
.ratio-summary .summary-item .score-badge {
  padding: 3px 10px;
  border-radius: 10px;
  font-weight: bold;
  font-size: 13px;
}

.growth-summary .summary-item .z-value,
.ratio-summary .summary-item .z-value {
  font-size: 11px;
  color: #999;
  font-family: monospace;
  margin-left: 5px;
}

.growth-summary .summary-item .rank-badge,
.ratio-summary .summary-item .rank-badge {
  padding: 3px 10px;
  background: linear-gradient(135deg, #ffd700 0%, #ffed4e 100%);
  border-radius: 10px;
  font-weight: bold;
  font-size: 13px;
  color: #8b6914;
}

.indicator-error {
  padding: 15px;
  background: #fff2f0;
  border-radius: 4px;
  color: #cf1322;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: #999;
  font-size: 16px;
}

.empty-state .hint {
  margin-top: 10px;
  font-size: 14px;
  color: #bbb;
}

.branches-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.branch-item {
  border: 2px solid #d9d9d9;
  border-radius: 8px;
  overflow: hidden;
  background: white;
}

.branch-header {
  padding: 15px 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: all 0.3s;
}

.branch-header:hover {
  background: linear-gradient(135deg, #5568d3 0%, #6a3f8f 100%);
}

.branch-header h3 {
  margin: 0;
  font-size: 18px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.toggle-icon {
  font-size: 14px;
  transition: transform 0.3s;
}

.branch-stats {
  display: flex;
  gap: 15px;
}

.branch-stats .stat {
  padding: 4px 12px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
}

.branch-stats .stat.success {
  background: rgba(82, 196, 26, 0.3);
}

.branch-stats .stat.fail {
  background: rgba(255, 77, 79, 0.3);
}

.branch-stats .stat.weighted-sum {
  background: rgba(250, 140, 22, 0.3);
  font-weight: 700;
  font-size: 15px;
  color: #d46b08;
  border: 2px solid #fa8c16;
}

.branch-stats .stat.weight-info {
  background: rgba(24, 144, 255, 0.3);
  font-weight: 600;
  color: #0050b3;
}

.branch-stats .stat.score {
  background: rgba(102, 126, 234, 0.3);
  font-weight: 600;
}

.branch-stats .stat.rank {
  background: rgba(255, 215, 0, 0.3);
  font-weight: 600;
}

.branch-content {
  padding: 20px;
  background: #fafafa;
}

/* 评分和排名单元格样式 */
.score-cell {
  text-align: center;
  min-width: 150px;
}

.score-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.score-badge {
  padding: 4px 12px;
  border-radius: 12px;
  font-weight: bold;
  font-size: 14px;
  white-space: nowrap;
}

.score-badge.excellent {
  background: #e6fffb;
  color: #00b96b;
}

.score-badge.good {
  background: #e6f7ff;
  color: #1890ff;
}

.score-badge.fair {
  background: #fff7e6;
  color: #faad14;
}

.score-badge.poor {
  background: #fff2f0;
  color: #ff4d4f;
}

.z-value {
  font-size: 11px;
  color: #999;
  font-family: monospace;
}

.no-score {
  color: #ccc;
}

.rank-cell {
  text-align: center;
  min-width: 80px;
}

.rank-badge {
  display: inline-block;
  padding: 4px 12px;
  background: linear-gradient(135deg, #ffd700 0%, #ffed4e 100%);
  border-radius: 12px;
  font-weight: bold;
  font-size: 14px;
  color: #8b6914;
}

.weight-badge {
  display: inline-block;
  padding: 4px 12px;
  background: linear-gradient(135deg, #e6f7ff 0%, #bae7ff 100%);
  border-radius: 12px;
  font-weight: bold;
  font-size: 14px;
  color: #0050b3;
}

.weighted-score {
  margin-left: 8px;
  color: #fa8c16;
  font-weight: bold;
  font-size: 14px;
}

.weighted-score-cell {
  text-align: center;
  min-width: 100px;
}

.weighted-score-value {
  display: inline-block;
  padding: 4px 12px;
  background: linear-gradient(135deg, #fff7e6 0%, #ffe7ba 100%);
  border-radius: 12px;
  font-weight: bold;
  font-size: 14px;
  color: #d46b08;
}

.no-rank,
.no-weight,
.no-weighted-score {
  color: #ccc;
}

/* 异常指标样式 */
.stat.abnormal {
  background: linear-gradient(135deg, #ff6b6b 0%, #ff8e53 100%);
  color: white;
  font-weight: bold;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.8;
  }
}

.abnormal-indicators {
  margin-top: 12px;
  padding: 12px;
  background: linear-gradient(135deg, rgba(255, 107, 107, 0.1) 0%, rgba(255, 142, 83, 0.1) 100%);
  border-left: 4px solid #ff6b6b;
  border-radius: 8px;
}

.abnormal-title {
  font-size: 14px;
  font-weight: bold;
  color: #ff4d4f;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.abnormal-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.abnormal-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: white;
  border-radius: 6px;
  font-size: 12px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

.abnormal-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.abnormal-item.high-risk {
  border-left: 3px solid #ff4d4f;
}

.abnormal-item.excellent {
  border-left: 3px solid #52c41a;
}

.abnormal-item .indicator-name {
  font-weight: bold;
  color: #262626;
}

.abnormal-item .indicator-value {
  color: #595959;
}

.abnormal-item .indicator-zscore {
  font-weight: bold;
  padding: 2px 8px;
  border-radius: 4px;
  font-family: monospace;
}

.abnormal-item .indicator-zscore.zscore-high {
  background: #fff2f0;
  color: #ff4d4f;
}

.abnormal-item .indicator-zscore.zscore-low {
  background: #f6ffed;
  color: #52c41a;
}

.abnormal-item .indicator-score {
  color: #8c8c8c;
  font-size: 11px;
}
</style>

